# 保留了继承自Activity、Application这些类的子类 # 因为这些子类,都有可能被外部调用 # 比如说,第一行就保证了所有Activity的子类不要被混淆 -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
# 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.**
# 保留 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.**
# 保留在Activity中的方法参数是view的方法, # 从而我们在layout里面编写onClick就不会被影响 -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); }
# 保留自定义控件(继承自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); }
-keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet, int); }
# 保留所有的本地native方法不被混淆 -keepclasseswithmembernames class * { native <methods>; }
# 枚举类不能被混淆 -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
# 保留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$* { *; } #-------------------------webview(项目中没有使用可以忽略)------------------------------ -keepclassmembers class fqcn.of.javascript.interface.for.Webview { public *; } -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, jav.lang.String); } # ----------------------------- 其他的 ----------------------------- # # 删除代码中Log相关的代码 -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(...); }