Android开发的都应该知道混淆,这是app上线前必须要走的流程, 混淆的重要性本文就不多说了,下面直接贴快速混淆的代码,大家可以直接copy。
- build.gradle中打开混淆 minifyEnabled true;
#-----------------------------------------------START----------------------------------------------------
#-------------------------------------------定制化区域 START----------------------------------------------
#---------------------------------1.实体类 START---------------------------------
#todo
#---------------------------------1.实体类 END---------------------------------
#---------------------------------2.第三方包 START-------------------------------
#todo
#---------------------------------2.第三方包 END-------------------------------
#---------------------------------3.与js互相调用的类 START------------------------
#todo
#---------------------------------3.与js互相调用的类 END------------------------
#---------------------------------4.反射相关的类和方法 START-----------------------
#todo
#---------------------------------4.反射相关的类和方法 END-----------------------
#-------------------------------------------定制化区域 END----------------------------------------------
#-------------------------------------------基本不用动区域--------------------------------------------
#---------------------------------基本指令区----------------------------------
#代码混淆的压缩比例,值在0-7之间
-optimizationpasses 5
#指定不去忽略非公共的库的类的成员
-dontskipnonpubliclibraryclassmembers
#生成原类名和混淆后的类名的映射文件
-printmapping proguardMapping.txt
-optimizations !code/simplification/cast,!field/*,!class/merging/*
-keepattributes *Annotation*,InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
#----------------------------------------------------------------------------
#---------------------------------默认保留区---------------------------------
-keep public class * extends android.app.Activity
-keep public class * extends android.support.v7.app.AppCompatActivity
-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 class android.support.** {*;}
-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);
}
-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();
}
-keep class **.R$* {
*;
}
-keepclassmembers class * {
void *(**On*Event);
}
#----------------------------------------------------------------------------
#---------------------------------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);
}
#----------------------------------------------------------------------------
#-----------------------------------------------over----------------------------------------------------