Dexguard always crash with enum

751 views Asked by At

I'm using DexGuard Enterprise for my apps. And I find that whenever I use a library that have ENUM in it (for eg: ZXing), DexGuard did something to the code that my app would crash with errors like

java.lang.AssertionError: impossible
at java.lang.Enum$1.create(Enum.java:49)
at java.lang.Enum$1.create(Enum.java:35)
at libcore.util.BasicLruCache.get(BasicLruCache.java:54)
at java.lang.Enum.getSharedConstants(Enum.java:211)
at java.lang.Enum.valueOf(Enum.java:191)
at com.google.zxing.BarcodeFormat.valueOf(:24)

I tried options such as these (as I found them on other questions), but not working

-keep enum com.google.zxing.** {
    *;
}

what seems to be the problem? How could I fix it? It's bugging me for weeks now.

2

There are 2 answers

0
Cheok Yan Cheng On

Try to add the following in your proguard file.

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

You can add allowoptimization also

   -keepclassmembers,allowoptimization enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }

https://www.guardsquare.com/en/products/proguard/manual/examples#enumerations