至于它是
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
怎样指定 proguard-rules.pro 文件来配置代码混淆的,我们可以在看一下 build.gradle 是怎样配置的
// 对正式版的进行混淆配置
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
}
}
了解了在哪里配置混淆代码之后,下面我们一起来看一下怎样混淆代码
首先,我们先来看一下 Android 默认的代码混淆配置,在 {SDKHOME}\tools\proguard 目录下,有 proguard-android.txt 文件,该文件就是默认的代码混淆配置
This is a configuration file for ProGuard.
http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
Optimization is turned off by default. Dex does not like code run
through the ProGuard optimize and preverify steps (and performs some
of these optimizations on its own).
-dontoptimize
-dontpreverify
Note that if you want to enable optimization, you cannot just
include optimization flags in your own project configuration file;
instead you will need to point to the
“proguard-android-optimize.txt” file instead of this one from your
project.properties file.
-keepattributes Annotation
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native ;
}
keep setters in Views so that animations can still work.
see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class *.R$ {
public static ;
}