# Annotation注释不能混淆 -keepattributes *Annotation* #对于NDK开发 本地的native方法不能被混淆 -keepclasseswithmembernames class * { native <methods>; } #保持View的子类里面的set、get方法不被混淆(*代替任意字符) -keepclassmembers public class * extends android.view.View { void set*(***); *** get*(); }
#保持Activity子类里面的参数类型为View的方法不被混淆,如被XML里面应用的onClick方法 # We want to keep methods in Activity that could be used in the XML attribute onClick -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); }
#保持枚举类型values()、以及valueOf(java.lang.String)成员不被混淆 -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
#保持实现Parcelable接口的类里面的Creator成员不被混淆 -keepclassmembers class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator CREATOR; }
#保持R类静态成员不被混淆 -keepclassmembers class **.R$* { public static <fields>; }
#不警告support包中不使用的引用 -dontwarn android.support.** -keep class android.support.annotation.Keep -keep @android.support.annotation.Keep class * {*;} #保持使用了Keep注解的方法以及类不被混淆 -keepclasseswithmembers class * { @android.support.annotation.Keep <methods>; } #保持使用了Keep注解的成员域以及类不被混淆 -keepclasseswithmembers class * { @android.support.annotation.Keep <fields>; } -keepclasseswithmembers class * { @android.support.annotation.Keep <init>(...); }
# 删除日志 (一定要把 -dontoptimize 配置去掉,否则无法删除日志) -assumenosideeffects class org.apache.log4j.** {*;} -assumenosideeffects class de.mindpipe.android.logging.log4j.LogConfigurator {*;} -assumenosideeffects class android.util.Log { public static boolean isLoggable(java.lang.String, int); public static int v(...); public static int i(...); public static int w(...); public static int d(...); public static int e(...); }