Android studio 代碼混淆

    #指定代碼的壓縮級別
    -optimizationpasses 5

    #包明不混合大小寫
    -dontusemixedcaseclassnames

    #不去忽略非公共的庫類
    -dontskipnonpubliclibraryclasses

     #優化  不優化輸入的類文件
    -dontoptimize

     #預校驗
    -dontpreverify

     #混淆時是否記錄日誌
    -verbose

     # 混淆時所採用的算法
    -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

    #保護註解
    -keepattributes *Annotation*

    # 保持哪些類不被混淆
    -keep public class * extends android.app.Fragment
    -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
    #若是有引用v4包能夠添加下面這行
    -keep public class * extends android.support.v4.app.Fragment


    #忽略警告
    -ignorewarning

    ##記錄生成的日誌數據,gradle build時在本項目根目錄輸出##

    #apk 包內全部 class 的內部結構
    -dump class_files.txt
    #未混淆的類和成員
    -printseeds seeds.txt
    #列出從 apk 中刪除的代碼
    -printusage unused.txt
    #混淆先後的映射
    -printmapping mapping.txt

    ########記錄生成的日誌數據,gradle build時 在本項目根目錄輸出-end######


    #####混淆保護本身項目的部分代碼以及引用的第三方jar包library#######

    #-libraryjars libs/umeng-analytics-v5.2.4.jar

    #三星應用市場須要添加:sdk-v1.0.0.jar,look-v1.0.1.jar
    #-libraryjars libs/sdk-v1.0.0.jar
    #-libraryjars libs/look-v1.0.1.jar


    #若是引用了v4或者v7包
    -dontwarn android.support.**

    ####混淆保護本身項目的部分代碼以及引用的第三方jar包library-end####

    -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*(...);
    }

    #保持 native 方法不被混淆
    -keepclasseswithmembernames class * {
        native <methods>;
    }

    #保持自定義控件類不被混淆
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }

    #保持自定義控件類不被混淆
    -keepclassmembers class * extends android.app.Activity {
       public void *(android.view.View);
    }

    #保持 Parcelable 不被混淆
    -keep class * implements android.os.Parcelable {
      public static final android.os.Parcelable$Creator *;
    }

    #保持 Serializable 不被混淆
    -keepnames class * implements java.io.Serializable

    #保持 Serializable 不被混淆而且enum 類也不被混淆
    -keepclassmembers class * implements java.io.Serializable {
        static final long serialVersionUID;
        private static final java.io.ObjectStreamField[] serialPersistentFields;
        !static !transient <fields>;
        !private <fields>;
        !private <methods>;
        private void writeObject(java.io.ObjectOutputStream);
        private void readObject(java.io.ObjectInputStream);
        java.lang.Object writeReplace();
        java.lang.Object readResolve();
    }

    #保持枚舉 enum 類不被混淆 若是混淆報錯,建議直接使用上面的 -keepclassmembers class * implements java.io.Serializable便可
    -keepclassmembers enum * {
      public static **[] values();
      public static ** valueOf(java.lang.String);
    }

    -keepclassmembers class * {
        public void *ButtonClicked(android.view.View);
    }

    #不混淆資源類
    -keepclassmembers class **.R$* {
        public static <fields>;
    }

    #---------------------------------實體類------------------------------------
    #若是不想混淆 keep 掉
    #忽略警告
    -dontwarn leadtech.xufeng.android.com.utils**
    #保留一個完整的包
    -keep class leadtech.xufeng.android.com.utils.** {*;}

    #---------------------------------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);
#    }

    #---------------------------------js調用-------------------------------------

#   -keepclasseswithmembers class com.demo.login.bean.ui.MainActivity$JSInterface {
#           <methods>;
#   }
#           webview中js對象
#   -keepclassmembers class com.ulucu.fragment.PayFragment$JavaScriptObject {
#       public *;
#   }

    #---------------------------------第三方包-------------------------------
    #若是用用到Gson解析包的,直接添加下面這幾行就能成功混淆,否則會報錯。
    #gson
    #-libraryjars libs/gson-2.2.2.jar
    -keepattributes Signature
    # Gson specific classes
    -keep class sun.misc.Unsafe { *; }
    # Application classes that will be serialized/deserialized over Gson
    -keep class com.google.gson.examples.android.model.** { *; }

    #okhttputils
    -dontwarn com.zhy.http.**
    -keep class com.zhy.http.**{*;}

    #okhttp
    -dontwarn okhttp3.**
    -keep class okhttp3.**{*;}

    #okio
    -dontwarn okio.**
    -keep class okio.**{*;}

    #glide
    -keep public class * implements com.bumptech.glide.module.GlideModule
    -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
      **[] $VALUES;
      public *;
    }
    -keep class com.bumptech.glide.** { *; }

    #biadu
    -keep class com.baidu.** { *; }
    -keep class vi.com.gdi.bgl.android.**{*;}
    -dontwarn com.baidu.**

#    #友盟
#    -keep class com.umeng.**{*;}
相關文章
相關標籤/搜索