Shajeel Afzal
Shajeel Afzal

Reputation: 5953

Android crash while using GSON Library and ProGuard

I am using the following Proguard configuration with GSON library:

# 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.** { *; }

# Keep any class that intereracts with GSON
-keep class com.trifecta.engine.api.** { *; }

But while testing exported apk i am getting the error:

Caused by: java.lang.AbstractMethodError: abstract method 
"void com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$a.a(com.google.gson.stream.JsonWriter, java.lang.Object)"
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:200)
       at com.google.gson.Gson.toJson(Gson.java:546)
       at com.google.gson.Gson.toJson(Gson.java:525)
       at com.google.gson.Gson.toJson(Gson.java:480)
       at com.google.gson.Gson.toJson(Gson.java:460)

I have researched for the problem here on SO and i followed the Proguard configuration from: [https://code.google.com/p/google-gson/source/browse/trunk/examples/android-proguard-example/proguard.cfg] but still no success. 1

Upvotes: 3

Views: 1252

Answers (1)

williamj949
williamj949

Reputation: 11316

try this snippet and let me know

## GSON 2.2.4 specific rules ##

# 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*

-keepattributes EnclosingMethod

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }

Upvotes: 3

Related Questions