工程中使用了fastjson,无奈,对工程做混淆的时候总是报错过不去,后来过去了又出现使用fastjson的地方数据不正确的问题,试了好多办法才成功,废话不多说,添加的代码:
##---------------Begin: proguard configuration for fastjson ---------- #-keepnames class * implements java.io.Serializable -keep public class * implements java.io.Serializable { public *; } -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(); } -dontwarn android.support.** -dontwarn com.alibaba.fastjson.** -dontskipnonpubliclibraryclassmembers -dontskipnonpubliclibraryclasses -libraryjars libs/fastjson.jar -keep class com.alibaba.fastjson.** { *; } -keepclassmembers class * { public <methods>; } ##---------------End: proguard configuration for fastjson ----------Gson的混淆:
##---------------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 cn.howie.base.data.** { *; } -keep class cn.howie.base.bean.** { *; }
##---------------End: proguard configuration for Gson ----------
其中红色部分必须为自己项目中的实体类,否则混淆后无法正常显示数据,网上有好多博客都很坑,直接把google文档的代码直接贴出来了,一定要修改红色部分。