我正试图用R8全模式构建应用程序的发布版本,但这会导致崩溃。更具体地说,当通过Android Studio进行安装时,要么构建将完全正常,要么它将在下面添加堆栈时立即崩溃。
有时它会在配置更改后立即发生,例如debuggable false
到debuggable true
,有时还会在同一渐变配置的连续构建后发生,这非常奇怪,我无法确定它的行为。
release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
minifyEnabled true
debuggable false
shrinkResources true
}
Proguard文件:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
## kotlin
-dontwarn org.jetbrains.annotations.**
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.reflect.jvm.internal.**
-keep class kotlin.reflect.jvm.internal.* { *; }
-keepclassmembers class kotlin.Metadata {
public <methods>;
}
-keepnames @dagger.hilt.android.lifecycle.HiltViewModel class * extends androidx.lifecycle.ViewModel
该应用程序是用构建的
- Android Studio 4.2.1
- AGP版本4.2.1
- Gradle版本Gradle-6.7.1-全部
由于包含Jetpack Compose,我们还添加了:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += [
"-Xallow-jvm-ir-dependencies",
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
]
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
此外,还包括可能的解决方案CCD_ 3和CCD_ 4。
崩溃1:
E/zd3: SafeAtomicHelper is broken!
java.lang.ClassCastException
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:352)
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:109)
at zd3.<clinit>(Unknown Source:96)
at be3.t(Unknown Source:46)
at d93.<init>(Unknown Source:41)
at ad3.<init>(Unknown Source:77)
at i93.a(Unknown Source:186)
at r93.c(Unknown Source:410)
at qg8.<init>(Unknown Source:247)
at og8.b(Unknown Source:108)
at MyAppApplication.c(Unknown Source:74)
at MyAppApplication.onCreate(Unknown Source:44)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7184)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7134)
at android.app.ActivityThread.access$1500(ActivityThread.java:274)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2102)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
崩溃2:
Fatal Exception: java.lang.ExceptionInInitializerError
at kotlin.LazyKt__LazyJVMKt.lazy(LazyKt__LazyJVMKt.java:34)
at kotlin.reflect.jvm.internal.KProperty1Impl.<init>(KProperty1Impl.java:41)
at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.property1(ReflectionFactoryImpl.java:18)
at kotlin.jvm.internal.Reflection.property1(Reflection.java:2)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl$Data.<clinit>(KDeclarationContainerImpl.java:18)
at kotlin.reflect.jvm.internal.KClassImpl$data$1.invoke(KClassImpl.java)
at kotlin.reflect.jvm.internal.KClassImpl$data$1.invoke(KClassImpl.java)
at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:11)
at kotlin.reflect.jvm.internal.KClassImpl.getSimpleName(KClassImpl.java:2)
at com.android.tools.r8.GeneratedOutlineSupport.outline55(GeneratedOutlineSupport.java:4)
at MyAppViewModel.subscribe(MyAppViewModel.java:2)
at MyAppActivity.onResume(MyAppActivity.java:26)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1454)
at android.app.Activity.performResume(Activity.java:8111)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4647)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4690)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by java.lang.ClassCastException
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:352)
at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:109)
at kotlin.SafePublicationLazyImpl.<clinit>(SafePublicationLazyImpl.java:6)
at kotlin.LazyKt__LazyJVMKt.lazy(LazyKt__LazyJVMKt.java:34)
at kotlin.reflect.jvm.internal.KProperty1Impl.<init>(KProperty1Impl.java:41)
at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.property1(ReflectionFactoryImpl.java:18)
at kotlin.jvm.internal.Reflection.property1(Reflection.java:2)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl$Data.<clinit>(KDeclarationContainerImpl.java:18)
at kotlin.reflect.jvm.internal.KClassImpl$data$1.invoke(KClassImpl.java)
at kotlin.reflect.jvm.internal.KClassImpl$data$1.invoke(KClassImpl.java)
at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:11)
at kotlin.reflect.jvm.internal.KClassImpl.getSimpleName(KClassImpl.java:2)
at com.android.tools.r8.GeneratedOutlineSupport.outline55(GeneratedOutlineSupport.java:4)
at MyAppViewModel.subscribe(MyAppViewModel.java:2)
at MyAppActivity.onResume(MyAppActivity.java:26)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1454)
at android.app.Activity.performResume(Activity.java:8111)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4647)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4690)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
回答我自己的问题。解决方法是在proguard-rules.pro:中添加以下规则
-keepclassmembers class kotlin.SafePublicationLazyImpl {
java.lang.Object _value;
}
问题在谷歌的issuetracker 上跟踪