代码混淆 - Gson解析bug

    项目中使用Gson解析json数据,未做混淆处理时,网络访问及解析json数据正常。作代码混淆时,依据官方demo,配置Gson的混淆。混淆后,网络访问出现了问题,数据不能正常加载。Debug跟踪发现,网络访问获取数据正常,在Gson解析时出现了问题。很撸google发现了问题所在。


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

       请注意倒数第二行,红色特别标注的那一行,这是google官方的proguard的文档,,class 后方到**签名的是google的包名,而实际上应改成所有应用Gson的java bean定义的目录,如此bug解除了.

## ----------------------------------
##   ########## Gson混淆    ##########
## ----------------------------------
-libraryjars  libs/gson-2.2.4.jar
-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
-keep class com.google.**{*;}
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}
# 需
# XXX.XX.XXX
# 改成所有Java bean 存放的包名-keep class XXX.XX.XXX.** { *; }-keep class org.json.** {*;}
 
  

         Bug记录在案,以备后查!



你可能感兴趣的:(代码混淆 - Gson解析bug)