android studio混淆

将gradle文件中的minifyEnabled设置为true,然后再在proguard-rules.pro中添加规则就行了。

常用的混淆:

-keepclasseswithmembernames class * { # 保持 native 方法不被混淆 
   native <methods>;
}
-keepclasseswithmembers class * { # 保持自定义控件类不被混淆 
   public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {# 保持自定义控件类不被混淆 
   public <init>(android.content.Context, android.util.AttributeSet, int); 
}
-keepclassmembers class * extends android.app.Activity { # 保持自定义控件类不被混淆  
   public void *(android.view.View);
}
-keepclassmembers enum * { # 保持枚举 enum 类不被混淆  
   public static **[] values(); 
   public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {#保持Parcelable不被混淆
   public static final android.os.Parcelable$Creator *;
}
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keep public class * implements java.io.Serializable {*;}
-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();
}

 

android中还可以使用注解方法来避免混淆,只要在想要避免混淆处添加@keep即可,类、方法、变量都可使用

posted @ 2016-06-22 16:53  maozs  阅读(143)  评论(0编辑  收藏  举报