GuilhE GuilhE - 1 year ago 202
Android Question

Android Proguard ExceptionInInitializerError and RuntimeException

I want to obfuscate my .apk and I'm having some troubles with Proguard. Using eclipse I've enabled this:

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):

I'm using 4 external libs:

  • android-support-v4.jar

  • nine-old-android-lib.jar

  • gson-2.2.2.jar

  • commons-io-2.4.jar

I guess I'm having trouble with gson:

private static Type MY_DATA_TYPE = new TypeToken<Pair<Map<Point, Void>, Integer>>() {}.getType();

Every time I use it:

java.lang.ExceptionInInitializerError at com.myapp.MyActivity.onCreate(Unknown Source)


Caused by: java.lang.RuntimeException: Missing type parameter.
at Source)
at<init>(Unknown Source)

I'm using this options but I guess it wont help:

-keepattributes Exceptions, InnerClasses, *Annotation*, EnclosingMethod

-libraryjars .../libs/android-support-v4.jar
-libraryjars .../libs/nine-old-android-lib.jar
-libraryjars .../libs/gson-2.2.2.jar
-libraryjars .../libs/commons-io-2.4.jar

-keep class java.** { *; }
-keep class android.** { *; }
-keep class org.** { *; }
-keep class** { *; }
-keep class com.facebook.** { *; }
-keep class com.nineoldandroids.** { *; }

How can I solve this and create an obfuscated .apk that works properly?

Thanks for your time.

Answer Source

Guess this is a gson "problem", here's the solution:

-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
-keep class** { *; }

Thanks to!topic/google-gson/6XuHfOoZIKo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download