美文网首页
混淆规则

混淆规则

作者: 菜鸟何时起飞 | 来源:发表于2020-05-19 14:20 被阅读0次

1 异常和内部类

-keepattributes Exceptions,InnerClasses,...

2 泛型

-keepattributes Signature

3 注解

-keepattributes *Annotation*

4 抛出异常时保留代码行号

-keepattributes SourceFile,LineNumberTable

5 JS

-keepattributes *JavascriptInterface*

6 单个内部类不混淆规则

-keep interface some.demo$inner{*;}

7 常见继承不混淆

-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 com.android.vending.licensing.ILicensingService
-keep public class * extends android.widget.BaseAdapter {*;}

8 保持native方法不被混淆

-keepclasseswithmembernames class * { 
    native <methods>;
}

9 保留枚举enum类不被混淆

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

10 序列化不混淆

-keep class * implements android.os.Parcelable{
    public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class * implements java.io.Serializable {
   static final long serialVersionUID;
   private static final java.io.ObjectStreamField[] serialPersistentFields;
   !static !transient <fields>;
   private void writeObject(java.io.ObjectOutputStream);
   private void readObject(java.io.ObjectInputStream);
   java.lang.Object writeReplace();
   java.lang.Object readResolve();
}

11 不混淆资源、support中的v4和v7

-keepclassmembers class **.R$* { *; }
-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);
}
# support-v4
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep public class * extends android.support.v4.**
# support-v7
-dontwarn android.support.v7.**                                             #去掉警告
-keep class android.support.v7.** { *; }                                    #过滤android.support.v7
-keep interface android.support.v7.app.** { *; }
-keep public class * extends android.support.v7.**

12 自定义view

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(***);
    *** get* ();
}

13 回调函数

-keepclassmembers class * {
    void *(**On*Listener);
}

14 第三方引用

# 不混淆第三方引用的库
-dontskipnonpubliclibraryclasses

相关文章

网友评论

      本文标题:混淆规则

      本文链接:https://www.haomeiwen.com/subject/ieppohtx.html