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

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
本文介绍了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 中不可能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)
Error:Could not run build action using Gradle installation #39;C:Program FilesAndroidAndroid Studio1gradlegradle-2.2.1#39;(错误:无法使用 Gradle 安装 C:Program FilesAndroidAndroid Studio1gradlegradle-2.2.1 运行构建操作) - IT屋-程序员软件开发