码迷,mamicode.com
首页 > 其他好文 > 详细

Gson 防止被混淆

时间:2017-01-17 20:09:40      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:lang   pcl   rem   -keep   des   default   mat   ota   orm   

##---------------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 后方到**签名的 这一段包名应该是你所有的java bean 定义的目录(在写代码时,应该把java  bean 单独放在一个包中)。

另外附上,
1.Serializable 的配置

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn‘t save them.
-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();
}

-keep public class * implements java.io.Serializable {*;}
2.可以在proguard中 强制使所有混淆失效
-dontobfuscate
-dontoptimize
转载:http://blog.sina.com.cn/s/blog_4e1e357d0101ednf.html

Gson 防止被混淆

标签:lang   pcl   rem   -keep   des   default   mat   ota   orm   

原文地址:http://www.cnblogs.com/shiyeguiji/p/6294193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!