# Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # 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 *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile ###########################通用配置start######################################### #1.基本指令区 # 代码混淆压缩比,在0~7之间,默认为5,一般不做修改 -optimizationpasses 5 # 混合时不使用大小写混合,混合后的类名为小写 -dontusemixedcaseclassnames # 指定不去忽略非公共库的类 -dontskipnonpubliclibraryclasses # 指定不去忽略非公共库的类成员 -dontskipnonpubliclibraryclassmembers # 不进行优化,建议使用此选项, -dontoptimize # 不做预校验,preverify是proguard的四个步骤之一,Android不需要preverify 能够加快混淆速度。 -dontpreverify # 使我们的项目混淆后产生映射文件包含有类名->混淆后类名的映射关系 -verbose # 使用printmapping指定映射文件的名称 -printmapping proguardMapping.txt # 屏蔽警告 -ignorewarnings # 指定混淆是采用的算法,后面的参数是一个过滤器这个过滤器是谷歌推荐的算法,一般不做更改 -optimizations !code/simplification/cast,!field/*,!class/merging/* #添加支持的jar(引入libs下的所有jar包) #-libraryjars libs(*.jar) #将文件来源重命名为“SourceFile”字符串 -renamesourcefileattribute SourceFile # 保留Annotation不混淆 -keepattributes *Annotation* -keep class * extends java.lang.annotation.Annotation {*;} # 避免混淆泛型 -keepattributes Signature #保持反射不被混淆 -keepattributes EnclosingMethod #保持异常不被混淆 -keepattributes Exceptions #保持内部类不被混淆 -keepattributes Exceptions,InnerClasses # 抛出异常时保留代码行号 -keepattributes SourceFile,LineNumberTable #2.默认保留区 # 保留我们使用的四大组件,自定义的Application等等这些类不被混淆 # 因为这些子类都有可能被外部调用 -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.preference.Preference -keep public class * extends android.view.View -keep public class com.android.vending.licensing.ILicensingService -keep public class com.google.vending.licensing.ILicensingService # 保留support下的所有类及其内部类 -keep class android.support.** {*;} # 保留继承的 -keep public class * extends android.support.v4.** -keep public class * extends android.support.v7.** -keep public class * extends android.support.annotation.** -keep public class * extends androidx.appcompat.** -keep class com.google.android.material.** {*;} -keep class androidx.** {*;} -keep public class * extends androidx.** -keep interface androidx.** {*;} -dontwarn com.google.android.material.** -dontnote com.google.android.material.** -dontwarn androidx.** # 保留本地native方法不被混淆 -keepclasseswithmembernames class * { native ; } # 保留在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 (android.content.Context); public (android.content.Context, android.util.AttributeSet); public (android.content.Context, android.util.AttributeSet, int); } -keepclasseswithmembers class * { public (android.content.Context, android.util.AttributeSet); public (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(); } # 保留R下面的资源 -keep class **.R$* { *; } # 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆 -keepclassmembers class * { void *(**On*Event); void *(**On*Listener); } # 避免layout中onclick方法(android:onclick="onClick")混淆 -keepclassmembers class * extends android.app.Activity{ public void *(android.view.View); } # 对WebView的处理 -keepclassmembers class * extends android.webkit.webViewClient { public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); public boolean *(android.webkit.WebView, java.lang.String); } -keepclassmembers class * extends android.webkit.webViewClient { public void *(android.webkit.webView, java.lang.String); } -keepclassmembers class * { @android.webkit.JavascriptInterface ; } # AndroidX混淆 -keep class com.google.android.material.** {*;} -keep class androidx.** {*;} -keep public class * extends androidx.** -keep interface androidx.** {*;} -dontwarn com.google.android.material.** -dontnote com.google.android.material.** -dontwarn androidx.** ###########################通用配置end######################################### ###########################第三方库start######################################### #Architecture -dontwarn android.arch.** -keep public class android.arch.**{*;} #bugly -dontwarn com.tencent.bugly.** -keep public class com.tencent.bugly.**{*;} #okhttp -dontwarn okhttp3.** -dontwarn okio.** -dontwarn javax.annotation.** # A resource is loaded with a relative path so the package of this class must be preserved. -keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase #retrofit -dontwarn retrofit2.** -keep class retrofit2.** { *; } -keepattributes Exceptions #glide -keep public class * implements com.bumptech.glide.module.GlideModule -keep public class * extends com.bumptech.glide.module.AppGlideModule -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { **[] $VALUES; public *; } -dontwarn com.bumptech.glide.load.model.stream.** # EventBus -keepclassmembers class * { @org.greenrobot.eventbus.Subscribe ; } -keep enum org.greenrobot.eventbus.ThreadMode { *; } # Only required if you use AsyncExecutor -keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent { (java.lang.Throwable); } # Arouter -keep public class com.alibaba.android.arouter.routes.**{*;} -keep public class com.alibaba.android.arouter.facade.**{*;} -keep class * implements com.alibaba.android.arouter.facade.template.ISyringe{*;} ###########################第三方库end######################################### -keep class com.bbgo.common_base.bean.** {*;}