37

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

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

My build.gradle contains :

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

My proguard-project.txt contains

-useuniqueclassmembernames
-keepattributes SourceFile,LineNumberTable

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

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

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

Any known issue with Gradle + ProGuard ?

Thanks

0

2 Answers 2

63

You have to tell ProGuard to keep some enum methods.

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);
}

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')
Sign up to request clarification or add additional context in comments.

3 Comments

it looks like runProguard method is gone, so I just combined your two lines into proguardFiles getDefaultProguardFile('proguard-android.txt'), file("proguard-rules.txt")
@DraškoKokić: runProguard was renamed to minifyEnabled in Android Gradle plugin 1.0.0. (You do need to specify minifyEnabled true for your release build type; otherwise ProGuard will not be run.)
I try this fix and it works properly, but then I try reverting the change and just upgrading Gradle plugin version from 3.4.1 to 3.4.2 and it's fixed too. I don't know the reason but may be could help others.
0

Log of my error

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.zonaprop.android, PID: 20337
java.lang.AssertionError: Missing field in 
...
Caused by: java.lang.NoSuchFieldException: 
    at java.lang.Class.getField

The follow answer worked for me https://stackoverflow.com/a/30167048/5279996

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.