【问题标题】:Generating a Pro Guard configuration file with Android Studio使用 Android Studio 生成 Pro Guard 配置文件
【发布时间】:2013-08-07 21:38:14
【问题描述】:

我从 0.1.0 开始使用 Android Studio ...我昨天才得知 Pro Guard 似乎已集成到新创建的项目中。不幸的是,对于我的项目(这是一个前 Eclipse 项目)来说,情况并非如此。在我开始使用 Android Studio 之前,我不知道 Pro Guard。现在我正在寻找有关如何将 Pro Guard 与 Android Studio 一起使用的示例。不幸的是,Android Dev 文档只提到了配置文件已经创建的情况。是否有可能让 Android Studio 为现有项目创建配置文件?

【问题讨论】:

    标签: android proguard android-studio


    【解决方案1】:

    我也无法通过 Android Studio 做到这一点。但是,这对我有用。

    将以下部分添加到 build.gradle 文件的“android”部分,并在适当的地方填写您自己的实现细节。

    android {
    
    ...
    
        signingConfigs {
            releaseConfig {
                storeFile file("/dir/to/your.keystore")
                storePassword "xxx"
                keyAlias "yyy"
                keyPassword "xxx"
            }
        }
    
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), '../your_proguard_file.txt'
                signingConfig signingConfigs.releaseConfig
            }
        }
    }
    

    在您的项目文件夹中,运行 ./gradlew clean./gradlew assembleRelease

    【讨论】:

    • 您好,我已将您的配置应用到我的项目中,但它不起作用。我在那里发布了一个问题:stackoverflow.com/questions/18481752/… 谢谢你的帮助。
    • 重要的是要说你的代码应该包含在 android { ... } 但除此之外,它现在可以工作了。非常感谢!
    • 确实,你是对的 =) 看看tools.android.com/tech-docs/new-build-system/user-guide 总是好的
    • 重要,将您的 Build Variant 切换为“Release”
    • runProguard true 已更改为 minifyEnabled true
    【解决方案2】:

    您可以将默认的 Proguard 配置文件复制到您的项目中。

    sdk-location/tools/proguard/examples/android.pro — 将其复制并粘贴为项目中的 proguard.cfg。然后在 AS 询问配置文件路径时选择它。

    【讨论】:

    • 还注意到 Android Studio sdk 中的另一个示例。 sdk-location/tools/proguard/proguard-android.txt
    • 我尝试了 android.pro 文件并将其放入我的项目文件夹中。在“生成签名的 APK”期间选择它,但没有创建文件或目录来查看 ProGuard 的输出。我错过了什么吗?
    【解决方案3】:

    可以通过将-printconfiguration 命令附加到现有规则来保存由规则 (.pro) 文件生成的完整 ProGuard 配置。即

    -printconfiguration 'C:\Example\File\Path\proguard-configuration.txt'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      相关资源
      最近更新 更多