android - 如何准备混淆文件以及其中包含的内容?

标签 android gradle functional-programming android-gradle-plugin android-proguard

我正在 Android Studio 中开发一个应用程序,我想将混淆器添加到我的应用程序中。但我不知道该怎么办?我也想了解它的背景。谁能告诉我一些东西?谢谢。

最佳答案

在你的 gradle 文件中将 true 设置为 minifyEnabled

您可以定义是否在调试、发布或两者中启用 proguard

buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            proguardFiles 'proguard-rules.pro'
        }
    }

你也可以设置proguardFiles来配置他,检查这个site要查看有关它的文档,请看这个例子:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/balysv/Documents/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-optimizationpasses 5
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose

如果您想使用自定义字典进行代码混淆,请使用您的字典文件设置此配置:

-obfuscationdictionary proguard-dic.txt
-classobfuscationdictionary proguard-dic.txt
-packageobfuscationdictionary proguard-dic.txt

字典文件是一个简单的文本文件,其中包含您要用来混淆代码的标签,每行 1 个标签。

关于android - 如何准备混淆文件以及其中包含的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38213918/

相关文章:

android - ConstraintLayout 隐藏最后一行 TextView 与 app :layout_constrainedHeight ="true"

java - 生成时出错-找不到属性 'MyOpenWeatherMapApiKey'

eclipse - Libgdx:Gradle导入 eclipse 只显示根文件夹而不是项目

python - 棋盘覆盖递归算法背后的直觉是什么?如何更好地制定这种算法?

haskell - 无点函数实际上是如何 "functions"?

scala - 无形 : Prepend. 未找到隐式

android - 如何检查阻止对象符合垃圾收集条件的原因?

javascript - Ajax 请求支持 Android

java - Gradle:从外部编译的类生成jar

android - 如何在 Android Studio 中正确更改现有项目名称?