在 androidx.lifecycle.a.create (SourceFile:9) 中发布构建 Prugoard/R8 java.lang.ClassCastException

Release build Prugoard/R8 java.lang.ClassCastException at androidx.lifecycle.a.create(SourceFile:9)

提问人:user924 提问时间:9/6/2023 最后编辑:user924 更新时间:9/7/2023 访问量:106

问:

我真的不明白哪个库导致了发布版本中的问题,带有 或 的东西?minifyEnabled = trueandroidx.lifecycle....androidx.navigation.compose

我将导航撰写库从升级到其他一些,然后 mb 在此之后开始。无法降级,因为他们更改了导航合成库(对于某些动画内容)的许多依赖项,并且我已经进行了这些更改。2.6.*2.7.1

FATAL EXCEPTION: main
    Process: com.company_name.app_name, PID: 10694
    java.lang.ClassCastException
        at a.g.z(SourceFile:1)
        at l6.h.get(SourceFile:198)
        at j8.c.b(SourceFile:136)
        at androidx.lifecycle.a.create(SourceFile:9)
        at j8.f.create(SourceFile:2)
        at n4.t.p(SourceFile:73)
        at n4.t.o(SourceFile:13)
        at n4.f.E(SourceFile:45)
        at n4.f.n0(SourceFile:24)
        at u2.c.j(SourceFile:155)
        at v7.a.a(SourceFile:33)
        at v7.a.W(SourceFile:35)
        at o0.b.b(SourceFile:51)
        at o0.b.W(SourceFile:9)
        at s.d0.a(SourceFile:58)
        at s.d0.d0(SourceFile:66)
        at o0.b.d0(SourceFile:59)
        at q7.a.c(SourceFile:182)
        at p0.h.a(SourceFile:114)
        at v2.l.f(SourceFile:70)
        at androidx.navigation.compose.m.a(SourceFile:38)
        at androidx.navigation.compose.m.d0(SourceFile:17)
        at o0.b.d0(SourceFile:59)
        at q7.a.c(SourceFile:182)
        at v2.l.b(SourceFile:53)
        at androidx.navigation.compose.o.W(SourceFile:126)
        at o0.b.b(SourceFile:51)
        at o0.b.W(SourceFile:9)
        at p.k.a0(SourceFile:144)
        at o0.b.a(SourceFile:51)
        at o0.b.a0(SourceFile:9)
        at z.x0.b(SourceFile:1812)
        at z.x0.c(SourceFile:385)
        at p.l.a(SourceFile:320)
        at p.l.d0(SourceFile:41)
        at o0.b.d0(SourceFile:59)
        at kotlinx.coroutines.c0.b(SourceFile:1045)
        at o5.a.k(SourceFile:265)
        at androidx.navigation.compose.q.a(SourceFile:81)
        at androidx.navigation.compose.q.d0(SourceFile:29)
        at h0.w.L(SourceFile:287)
        at h0.w.U(SourceFile:58)
        at h0.w.r(SourceFile:166)
        at h0.w.K(SourceFile:36)
        at h0.c0.w(SourceFile:19)
        at h0.j2.o(SourceFile:96)
        at h0.g2.m0(SourceFile:363)
        at androidx.compose.ui.platform.u0.doFrame(SourceFile:7)
        at androidx.compose.ui.platform.s0.doFrame(SourceFile:48)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1229)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
        at android.view.Choreographer.doCallbacks(Choreographer.java:899)
        at android.view.Choreographer.doFrame(Choreographer.java:827)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
        at android.os.Handler.handleCallback(Handler.java:942)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
        Suppressed: kotlinx.coroutines.j0: [h0.o1@694f452, androidx.compose.ui.platform.s1@9493323, t1{Cancelling}@1d1a020, t0@dcb1dd9]

更新:通过添加到文件暂时解决 - https://stackoverflow.com/a/76694211/7767664android.enableR8.fullMode=falsegradle.properties

安卓 proguard android-r8 安卓组合

评论


答:

0赞 ObscureCookie 9/7/2023 #1

您可以使用 retrace CLI 工具和映射文件回溯堆栈跟踪。

  1. 将 proguard 规则添加到proguard-rules.pro
-keepattributes LineNumberTable,SourceFile
-renamesourcefileattribute SourceFile

这将使 R8 保留有关源文件和行号的信息。

  1. 创建要回溯的堆栈跟踪的文本文件。只需复制并粘贴跟踪即可。

  2. 使用 in 和 in 回溯文本文件。retrace.batcmdline-tools\bin\mapping.txt<module-name>\build\outputs\mapping\<build-type>\

编号 : https://developer.android.com/build/shrink-code#retracing