工程带有Fastjson或Gson等的第三方包的混淆配置

前端之家收集整理的这篇文章主要介绍了工程带有Fastjson或Gson等的第三方包的混淆配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

工程中使用了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文档的代码直接贴出来了,一定要修改红色部分。
原文链接:https://www.f2er.com/json/290326.html

猜你在找的Json相关文章