【Android 安全】DEX 加密 ( Proguard 简介 | 默认 ProGuard 分析 )
文章目錄
- 一、Proguard 配置簡介
- 二、Proguard 完整注釋
一、Proguard 配置簡介
更多 ProGuard 混淆配置參考 : https://www.guardsquare.com/en/products/proguard/manual/usage
1 . 不進行優化 :
# 不要進行優化 -dontoptimize2 . 混淆大小寫 : 不要使用混合大小寫類名進行混淆 , 混淆后的名稱全部都是小寫 , 增加閱讀難度
# 不要使用混合大小寫類名進行混淆 , 混淆后的名稱全部都是小寫 , 增加閱讀難度 -dontusemixedcaseclassnames3 . 保留反射屬性 : 保留一些反射中可能用到的屬性
# 保留一些反射中可能用到的屬性 -keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod4 . 保留這些類和類成員 :
# 保留這些類和類成員 -keep public class com.google.vending.licensing.ILicensingService5 . 控制日志輸出 : -dontnote , 控制編譯時不在 Build 對話框輸出一些日志信息 ;
# 控制編譯時不在 Build 對話框輸出一些日志信息 -dontnote com.android.vending.licensing.ILicensingService6 . Native 函數混淆設置 :
# 不混淆 Native 函數 # http://proguard.sourceforge.net/manual/examples.html#native -keepclasseswithmembernames class * {native <methods>; }7 . 保留類成員 , 包括成員函數 和 成員變量 :
# 不要混淆 Activity 及 子類的 成員 , 以防在 XML 的 onCLick 屬性中用到 . -keepclassmembers class * extends android.app.Activity {public void *(android.view.View); }8 . 保留注解 : 保留 android.support.annotation.Keep 注解類 , 不被混淆 ;
# 保留注解 -keep class android.support.annotation.Keep9 . 保留被注解聲明的類 : 被 @android.support.annotation.Keep 注解修飾的類不被混淆 ;
# 保留被 @android.support.annotation 注解聲明的類 -keep @android.support.annotation.Keep class * {*;}10 . 保留被注解聲明的函數 : 被 @android.support.annotation.Keep 注解修飾的函數不被混淆 ;
# 保留被 @android.support.annotation 注解聲明的函數 -keepclasseswithmembers class * {@android.support.annotation.Keep <methods>; }11 . 保留被注解聲明的成員 : 被 @android.support.annotation.Keep 注解修改的成員 , 不會被混淆 ;
# 保留被 @android.support.annotation 注解聲明的成員 -keepclasseswithmembers class * {@android.support.annotation.Keep <fields>; }12 . 保留被注解聲明的構造函數 : 被 @android.support.annotation.Keep 修飾的構造函數不會被混淆 ;
# 保留被 @android.support.annotation 注解聲明的構造函數 -keepclasseswithmembers class * {@android.support.annotation.Keep <init>(...); }二、Proguard 完整注釋
# This is a configuration file for ProGuard. # http://proguard.sourceforge.net/index.html#manual/usage.html # # 從 Gradle 插件 2.2 版本開始 , 該文件與插件一同發布, 在編譯構建時取出 . # 不再維護 $ANDROID_HOME 中的文件 , 新的 Gradle 插件版本將會忽略這些文件 . # # 默認情況下 , 優化會被關閉 . # Dex 自己會執行優化 , 不建議在 ProGuard 步驟中進行優化 . # 如果想要啟用優化 , 不能只在 ProGuard 項目配置中將優化標志設為 true ; # 相反還要在 build.gradle 中指向 "proguard-android-optimize.txt" 文件 . # 不要進行優化 -dontoptimize# 不要使用混合大小寫類名進行混淆 , 混淆后的名稱全部都是小寫 , 增加閱讀難度 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -verbose# 保留一些反射中可能用到的屬性 -keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod# 保留這些類和類成員 -keep public class com.google.vending.licensing.ILicensingService -keep public class com.android.vending.licensing.ILicensingService -keep public class com.google.android.vending.licensing.ILicensingService # 控制編譯時不在 Build 對話框輸出一些日志信息 -dontnote com.android.vending.licensing.ILicensingService -dontnote com.google.vending.licensing.ILicensingService -dontnote com.google.android.vending.licensing.ILicensingService# 不混淆 Native 函數 # http://proguard.sourceforge.net/manual/examples.html#native -keepclasseswithmembernames class * {native <methods>; }# 不要混淆繼承自 View 的 get set 函數 , 以便讓動畫可以繼續工作 # 指定類成員 ( 成員方法 / 成員變量 ) 不被混淆 -keepclassmembers public class * extends android.view.View {void set*(***);*** get*(); }# 不要混淆 Activity 及 子類的 成員 , 以防在 XML 的 onCLick 屬性中用到 . -keepclassmembers class * extends android.app.Activity {public void *(android.view.View); }# 枚舉成員不要混淆 # 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 ** CREATOR; }-keepclassmembers class **.R$* {public static <fields>; }# Preserve annotated Javascript interface methods. -keepclassmembers class * {@android.webkit.JavascriptInterface <methods>; }# The support libraries contains references to newer platform versions. # Don't warn about those in case this app is linking against an older # platform version. We know about them, and they are safe. -dontnote android.support.** -dontnote androidx.** -dontwarn android.support.** -dontwarn androidx.**# This class is deprecated, but remains for backward compatibility. -dontwarn android.util.FloatMath# Understand the @Keep support annotation. # 保留注解 -keep class android.support.annotation.Keep -keep class androidx.annotation.Keep# 保留被 @android.support.annotation 注解聲明的類 -keep @android.support.annotation.Keep class * {*;} # 保留被 @androidx.annotation 注解聲明的類 -keep @androidx.annotation.Keep class * {*;}# 保留被 @android.support.annotation 注解聲明的函數 -keepclasseswithmembers class * {@android.support.annotation.Keep <methods>; } # 保留被 @androidx.annotation 注解聲明的函數 -keepclasseswithmembers class * {@androidx.annotation.Keep <methods>; }# 保留被 @android.support.annotation 注解聲明的成員 -keepclasseswithmembers class * {@android.support.annotation.Keep <fields>; }# 保留被 @androidx.annotation 注解聲明的成員 -keepclasseswithmembers class * {@androidx.annotation.Keep <fields>; }# 保留被 @android.support.annotation 注解聲明的構造函數 -keepclasseswithmembers class * {@android.support.annotation.Keep <init>(...); }# 保留被 @androidx.annotation 注解聲明的構造方法 -keepclasseswithmembers class * {@androidx.annotation.Keep <init>(...); }# These classes are duplicated between android.jar and org.apache.http.legacy.jar. -dontnote org.apache.http.** -dontnote android.net.http.**# These classes are duplicated between android.jar and core-lambda-stubs.jar. -dontnote java.lang.invoke.**
總結
以上是生活随笔為你收集整理的【Android 安全】DEX 加密 ( Proguard 简介 | 默认 ProGuard 分析 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Android 安全】DEX 加密 (
- 下一篇: 【Android 安全】DEX 加密 (