标签:
在编写Android程序之后,我们通常要代码进行混淆编码,这样才能保证市场上我们的应用不会被别人进行反编译,然后破解,所以此时需要在发布正式版本的时候,有一些类事不能混淆的,比如实现了 Serializable 接口的,否则反序列化时会出错,这种情况下,我们可以简单的通过在proguard.cfg(Eclipse)添加配置来解决:
-keepnames class * implements java.io.Serializable -keepclassmembers class * implements java.io.Serializable { static final long serialVersionUID; private static final java.io.ObjectStreamField[] serialPersistentFields; !static !transient <fields>; private void writeObject(java.io.ObjectOutputStream); private void readObject(java.io.ObjectInputStream); java.lang.Object writeReplace(); java.lang.Object readResolve(); }
package cn.trinea.android.common.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * NotProguard, Means not proguard something, like class, method, field<br/> * * @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2015-08-07 */ @Retention(RetentionPolicy.CLASS) @Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) public @interface NotProguard { }
# keep annotated by NotProguard -keep @cn.trinea.android.common.annotation.NotProguard class * {*;} -keep class * { @cn.trinea.android.common.annotation.NotProguard <fields>; } -keepclassmembers class * { @cn.trinea.android.common.annotation.NotProguard <methods>; }
@NotProguard public class User {}
@NotProguard public int id;
@NotProguard public boolean isValid() { … }
标签:
原文地址:http://www.cnblogs.com/renhui/p/5863199.html