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

问题描述 投票:0回答:1

我真的不明白哪个库导致了发布版本中的问题,带有

minifyEnabled = true
,带有
androidx.lifecycle....
androidx.navigation.compose

我将导航撰写库从

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]

更新:通过将

android.enableR8.fullMode=false
添加到
gradle.properties
文件临时解决 - https://stackoverflow.com/a/76694211/7767664

android proguard android-r8 android-compose
1个回答
0
投票

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

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

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

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

  2. 使用

    retrace.bat
    中的
    cmdline-tools\bin\
    mapping.txt
    中的
    <module-name>\build\outputs\mapping\<build-type>\
    追溯文本文件。

参考:https://developer.android.com/build/shrink-code#retracing

© www.soinside.com 2019 - 2024. All rights reserved.