# The support library contains references to newer platform versions. # Don't warn about those in case this app is linking against an older # platform version. We know about them, and they are safe. -dontwarn android.support.**
#保留R下面的资源 -keep class **.R$* {*;}
#保留本地native方法不被混淆 -keepclasseswithmembernames class * { native <methods>; }
#保留在Activity中的方法参数是view的方法, #这样以来我们在layout中写的onClick就不会被影响 -keepclassmembers class * extends android.app.Activity{ public void *(android.view.View); }
#保留枚举类不被混淆 -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
#保留我们自定义控件(继承自View)不被混淆 -keep public class * extends android.view.View{ *** get*(); void set*(***); public <init>(android.content.Context); public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet, int); }
#保留Parcelable序列化类不被混淆 -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }
#保留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(); }
Set<File> proguardFiles = config.getProguardFiles(true /*includeLibs*/, ImmutableList.of(defaultProguardFile)); File proguardResFile = scope.getProcessAndroidResourcesProguardOutputFile(); proguardFiles.add(proguardResFile); // for tested app, we only care about their aapt config since the base // configs are the same files anyway. if (scope.getTestedVariantData() != null) { //和资源相关的混淆信息文件 proguardResFile = scope.getTestedVariantData().getScope() .getProcessAndroidResourcesProguardOutputFile(); proguardFiles.add(proguardResFile); } options.setProguardFiles(proguardFiles); options.setMappingFile(new File(scope.getProguardOutputFolder(), "mapping.txt")); }