Reputation: 11861
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):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
I'm using 4 external libs:
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:
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError at com.myapp.MyActivity.onCreate(Unknown Source)
...
Caused by: java.lang.RuntimeException: Missing type parameter.
at com.google.gson.reflect.TypeToken.getSuperclassTypeParameter(Unknown Source)
at com.google.gson.reflect.TypeToken.<init>(Unknown Source)
I'm using this options but I guess it wont help:
-keepattributes Exceptions, InnerClasses, *Annotation*, EnclosingMethod
-dontskipnonpubliclibraryclassmembers
-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 com.google.** { *; }
-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.
Upvotes: 3
Views: 4654
Reputation: 3037
Proguard configuration as shown by google gson proguard example.
google gson proguard configuration link
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
##---------------End: proguard configuration for Gson ----------
Upvotes: 1
Reputation: 11861
Guess this is a gson "problem", here's the solution:
-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.examples.android.model.** { *; }
Thanks to https://groups.google.com/forum/#!topic/google-gson/6XuHfOoZIKo
Upvotes: 8