Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android studio 混淆

Android studio 混淆

編輯:關於Android編程

-optimizationpasses 5                                                           # 指定代碼的壓縮級別  
-dontusemixedcaseclassnames                                                     # 是否使用大小寫混合  
-dontskipnonpubliclibraryclasses                                                # 是否混淆第三方jar  
-dontpreverify                                                                  # 混淆時是否做預校驗  
-verbose                                                                        # 混淆時是否記錄日志  
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*        # 混淆時所采用的算法  

-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              # 保持哪些類不被混淆  

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

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

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

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

-keepclassmembers enum * {                                                      # 保持枚舉 enum 類不被混淆  
    public static **[] values();  
    public static ** valueOf(java.lang.String);  
}  

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

-keep class MyClass;                                                            # 保持自己定義的類不被混淆  

我自己項目下的第三方混淆

-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod

-optimizations !code/simplification/arithmetic

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.content.ContentProvider


-keepclassmembers class * {
   void *(android.view.View);
   *** *Click(...);
   *** *Event(...);
}
-keep public class * {
    public protected *;
}
-keepclasseswithmembernames class * {
    native ;
}
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    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();
}
-keep public class * extends android.view.View {
    public (android.content.Context);
    public (android.content.Context, android.util.AttributeSet);
    public (android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}
-keepclasseswithmembers class * {
    public (android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
    public (android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
  public static ;
}
-keepclassmembers class * {
    @android.webkit.JavascriptInterface ;
}
-keep public interface com.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService


-dontpreverify
-repackageclasses ''
-allowaccessmodification

-dontwarn android.**
-keep interface android.** { *; }
-keep class android.** { *; }
-keep public class * extends android.**

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

-keep class com.fanglin.fenhong.microbuyer.base.model.** { *;}

#--------------- BEGIN: Gson防混淆 ----------
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
-keep class com.idea.fifaalarmclock.entity.***
#-keep class com.google.gson.stream.** { *; }
-keep class com.google.gson.** { *; }
#--------------- END ----------

-dontwarn com.daimajia.**
-keep class com.daimajia.** { *;}

#--------------- BEGIN:信鴿防混淆 ----------
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep class com.tencent.android.tpush.**  {* ;}
-keep class com.tencent.mid.**  {* ;}
#--------------- END ----------

#--------------- BEGIN: SafeWebViewBridge  ----------
-keepclassmembers class cn.pedant.SafeWebViewBridge.sample.HostJsScope$RetJavaObj{ *; }
-keepclassmembers class cn.pedant.SafeWebViewBridge.sample.HostJsScope{ *; }
#--------------- END ----------

# -----友盟-------------------
-keepclassmembers class * {
   public  (org.json.JSONObject);
}
-keep public class com.fanglin.fenhong.microbuyer.R$*{
   public static final int *;
}
#--------------- END ----------

最後在Builde.gradle中設置

buildTypes {
        release {
            // 不顯示Log  
            buildConfigField "boolean", "LOG_DEBUG", "false"  
            minifyEnabled true // 開啟混淆
            zipAlignEnabled true // 對齊zip
            shrinkResources false // 刪除無用資源
            debuggable false // 是否debug
            versionNameSuffix "_release" // 版本命名後綴
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // 混淆文件
        }

        debug {
            zipAlignEnabled false
            shrinkResources false
            minifyEnabled false
            versionNameSuffix "_debug"
            signingConfig signingConfigs.debug
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved