Android crash while using GSON Library and ProGuard

可紊 提交于 2021-02-07 09:44:35

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/28263210/android-crash-while-using-gson-library-and-proguard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!