我现在用的AndroidStudio , 只需要在 build.grade 的配置文件中配置如下即可:
buildTypes { debug { versionNameSuffix ".dev" } release { debuggable false minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } }
-libraryjars class_path 应用的依赖包,如android-support-v4 -keep [,modifier,...] class_specification 不混淆某些类 -keepclassmembers [,modifier,...] class_specification 不混淆类的成员 -keepclasseswithmembers [,modifier,...] class_specification 不混淆类及其成员 -keepnames class_specification 不混淆类及其成员名 -keepclassmembernames class_specification 不混淆类的成员名 -keepclasseswithmembernames class_specification 不混淆类及其成员名 -assumenosideeffects class_specification 假设调用不产生任何影响,在proguard代码优化时会将该调用remove掉。如system.out.println和Log.v等等 -dontwarn [class_filter] 不提示warnning
-keepattributes *Annotation*//使用注解需要添加 -keep public class com.google.vending.licensing.ILicensingService -keep public class com.android.vending.licensing.ILicensingService # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native -keepclasseswithmembernames class * {//指定不混淆所有的JNI方法 native <methods>; } # keep setters in Views so that animations can still work. # see http://proguard.sourceforge.net/manual/examples.html#beans -keepclassmembers public class * extends android.view.View {//所有View的子类及其子类的get、set方法都不进行混淆 void set*(***); *** get*(); } # We want to keep methods in Activity that could be used in the XML attribute onClick -keepclassmembers class * extends android.app.Activity {//不混淆Activity中参数类型为View的所有方法 public void *(android.view.View); } # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations -keepclassmembers enum * {//不混淆Enum类型的指定方法 public static **[] values(); public static ** valueOf(java.lang.String); } //不混淆Parcelable和它的子类,还有Creator成员变量 -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } //不混淆R类里及其所有内部static类中的所有static变量字段 -keepclassmembers class **.R$* { public static <fields>; } # 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.**//不提示兼容库的错误警告
-keepattributes Signature -keepattributes EnclosingMethod
-keep class czy.**{*;}//不混淆所有的com.czy.bean包下的类和这些类的所有成员变量继承了Serializable接口的类,需要加上:
//不混淆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(); }
-keepclassmembers class fqcn.of.javascript.interface.for.webview { public *; } -keep class com.xxx.xxx.** { *; }//保持WEB接口不被混淆 此处xxx.xxx是自己接口的包名
-keep class com.czy.**//不混淆所有com.czy包下的类,** 换成具体的类名则表示不混淆某个具体的类不混淆某个类和成员变量:
-keep class com.clock.**{*;}//不混淆所有com.clock包下的类和类中的所有成员变量,**可以换成具体类名,*可以换成具体的字段,可参照Serialzable的混淆
-assumenosideeffects class android.util.Log { public static *** v(...); public static *** i(...); public static *** d(...); public static *** w(...); public static *** e(...); }