Problem
GSON混淆后执行错误 java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to
Solution
I read from gson source through https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg, here is the content.
##—————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.* { ; }##—————End: proguard configuration for Gson ———-
总结一下
- 是不要混淆GsonJar包中的类
- 实现 java.io.Serializable的实体类中所有的属性名称也不能被混淆。
- 以及为了序列化和反序列化,writeObject(); readObject(); writeReplace(); readResolve();亦不可被混淆
Related Resource
http://xiaodongdong.blog.51cto.com/7049299/1353704
编写Android Proguard File