Android 发布 APK 因 java.lang.AssertionError 崩溃:在 ja

时间:2023-02-14
本文介绍了Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用 Gradle 构建了一个用于发布的 APK(ProGuard 4.9 并已签名).当我启动应用程序时,它会因此错误而崩溃:

I've just built an APK using Gradle for release (ProGuard 4.9 and signed). When I launch the app it crash on this error :

E/AndroidRuntime( 8662): java.lang.AssertionError: impossible
E/AndroidRuntime( 8662):    at java.lang.Enum$1.create(Enum.java:44)
E/AndroidRuntime( 8662):    at java.lang.Enum$1.create(Enum.java:35)
E/AndroidRuntime( 8662):    at libcore.util.BasicLruCache.get(BasicLruCache.java:54)
E/AndroidRuntime( 8662):    at java.lang.Enum.getSharedConstants(Enum.java:210)
E/AndroidRuntime( 8662):    at java.lang.Enum.valueOf(Enum.java:190)
E/AndroidRuntime( 8662):    at kr.infli.s.Z(Inflikr.java:390)
E/AndroidRuntime( 8662):    at kr.infli.a.ev(Inflikr.java:409)
E/AndroidRuntime( 8662):    at kr.infli.activity.InflikrActivity.onResume(InflikrActivity.java:231)
E/AndroidRuntime( 8662):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
E/AndroidRuntime( 8662):    at android.app.Activity.performResume(Activity.java:5310)
E/AndroidRuntime( 8662):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2778)
E/AndroidRuntime( 8662):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2817)
E/AndroidRuntime( 8662):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
E/AndroidRuntime( 8662):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 8662):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 8662):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 8662):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 8662):    at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 8662):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 8662):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 8662):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 8662): Caused by: java.lang.NoSuchMethodException: values []
E/AndroidRuntime( 8662):    at java.lang.Class.getMethod(Class.java:661)
E/AndroidRuntime( 8662):    at java.lang.Class.getDeclaredMethod(Class.java:623)
E/AndroidRuntime( 8662):    at java.lang.Enum$1.create(Enum.java:41)
E/AndroidRuntime( 8662):    ... 20 more

看起来这个错误不应该发生:https://android.googlesource.com/platform/libcore/+/9edf43dfcc35c761d97eb9156ac4254152ddbc55/libdvm/src/main/java/java/lang/Enum.java

Looks like this error should not happen : https://android.googlesource.com/platform/libcore/+/9edf43dfcc35c761d97eb9156ac4254152ddbc55/libdvm/src/main/java/java/lang/Enum.java

我的 build.gradle 包含:

My build.gradle contains :

buildTypes {
    release {
        runProguard true
        proguardFile file('./proguard-project.txt')
        signingConfig signingConfigs.release
    }
}

我的 proguard-project.txt 包含

My proguard-project.txt contains

-useuniqueclassmembernames
-keepattributes SourceFile,LineNumberTable

+ a bunch of keep class, dontnote, dontwarn,...

当我从 build.gradle 中删除 ProGuard 时,它不会崩溃.

When I remove ProGuard from build.gradle it do not crash.

当我在 Ant 构建中使用 ProGuard 时,它可以工作(我最近迁移到 Gradle).

When I was using ProGuard from an Ant build it worked (I recently migrated to Gradle).

Gradle + ProGuard 有任何已知问题吗?

Any known issue with Gradle + ProGuard ?

谢谢

推荐答案

你必须告诉 ProGuard 保留一些 enum 方法.

You have to tell ProGuard to keep some enum methods.

Android SDK 工具使用这个 ProGuard 配置来实现它:

The Android SDK tools use this ProGuard configuration to achieve it:

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

您可以将上述规则添加到您的 ProGuard 配置中,也可以(我更喜欢)包含默认的 Android 规则:

You can either add the above rule to your ProGuard configuration or you can (what I'd prefer) include the default Android rules:

minifyEnabled true
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile file('./proguard-project.txt')

这篇关于Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:以非零退出值 3 结束 下一篇:iOS5、UIScrollView 和 layoutSubviews 行为

相关文章

最新文章