首页  编辑  

自动混淆Release版本

Tags: /Android/   Date Created:
自动混淆Release版本,保护源代码,防止反编译:

buildTypes {
release {
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
shrinkResources true
debuggable false
jniDebuggable false
renderscriptDebuggable false
zipAlignEnabled true
pseudoLocalesEnabled false
}
debug {
signingConfig signingConfigs.debug
}
proguard-rules.pro文件,如果用了okhttp控件,需要用下面的规则文件,另外一半需要把安卓系统库的混淆去掉,否则可能程序运行时会崩溃,记住,混淆后,一定要测试一下所有功能:
-renamesourcefileattribute SourceFile
-dontwarn okio.**
-dontwarn com.squareup.okhttp3.**
-keep class com.squareup.okhttp3.** { *; }
-keep interface com.squareup.okhttp3.* { *; }
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}

-keep interface android.support.v4.** { *; }
-keep interface android.support.v7.** { *; }
-keep class android.support.** { *; }