# Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /Users/chenmengjia/Library/Android/sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} #默认的proguard-android.txt已经增加了Annotation、native、view的setget方法、Activity参数为view的方法、Enum枚举、Parcelable、R,此处不再写 #------------------------------------------通用区域---------------------------------------------------- #----------------------基本指令------------------------ #代码混淆压缩比,在0和7之间,默认为5,一般不需要改 -optimizationpasses 5 #混淆时不使用大小写混合,混淆后的类名为小写 -dontusemixedcaseclassnames #指定不去忽略非公共的库的类 -dontskipnonpubliclibraryclasses #指定不去忽略非公共的库的类的成员 -dontskipnonpubliclibraryclassmembers #不做预校验,preverify是proguard的4个步骤之一 #Android不需要preverify,去掉这一步可加快混淆速度 -dontpreverify #有了verbose这句话,混淆后就会生成映射文件 #包含有类名->混淆后类名的映射关系 #然后使用printmapping指定映射文件的名称 -verbose -printmapping proguardMapping.txt #指定混淆时采用的算法,后面的参数是一个过滤器 #这个过滤器是谷歌推荐的算法,一般不改变 -optimizations !code/simplification/cast,!field/*,!class/merging/* #保护代码中的Annotation不被混淆,这在JSON实体映射时非常重要,比如fastJson -keepattributes *Annotation*,InnerClasses #避免混淆泛型,这在JSON实体映射时非常重要,比如fastJson④ -keepattributes Signature #抛出异常时保留代码行号,在异常分析中可以方便定位 -keepattributes SourceFile,LineNumberTable #-----------------------全局混淆----------------------- #除了项目目录,其他都不混淆② -keep class !com.wang.**,!com.li.**,** {*;} -dontwarn ** #---------------------默认保留------------------------- #基础保留 -keep class * extends android.app.Activity -keep class * extends android.app.Application -keep class * extends android.app.Service -keep class * extends android.content.BroadcastReceiver -keep class * extends android.content.ContentProvider -keep class * extends android.app.backup.BackupAgentHelper -keep class * extends android.preference.Preference -keep class * extends android.view.View { (...); } #序列化 -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(); } #EventBus的注解 -keepclassmembers class * { @org.greenrobot.eventbus.Subscribe ; } #WebView -keepclassmembers class * extends android.webkit.WebView {*;} -keepclassmembers class * extends android.webkit.WebViewClient {*;} -keepclassmembers class * extends android.webkit.WebChromeClient {*;} -keepclassmembers class * { @android.webkit.JavascriptInterface ; } #-------------------------------------------项目定义区------------------------------------------------- #com.wang.*是为了适配其他项目③ #bean -keep class com.wang.*.bean** {*;} #eventbus传递的类 -keep class com.wang.*.eventbus.** {*;}