在 android studio 中设置 dexguard 许可证文件

Setting up dexguard license file in android studio

我在 dexguard.please 中没有找到 dexguard-license.txt 文件 请帮助我在 android studio 中进行 gradle 设置 这是我的 gradle 控制台输出

Executing tasks: [:app:assembleDebug]
.....
Can't find a DexGuard license file.
You should place your license file dexguard-license.txt
1) in a location defined by the Java system property 'dexguard.license',
2) in a location defined by the OS environment variable 'DEXGUARD_LICENSE',
3) in your home directory, 
4) in the class path, or
5) in the same directory as the DexGuard jar.

https://www.guardsquare.com

上登录帐户 > 文件页面后,即可下载许可证文件

看到这个screen shot

您应该将 dexguard-license.txt 文件和 dexguard.jar 文件复制到您的主目录(: /user/ironman).

已经有一段时间没有更新答案了,所以我想我会更新,因为 DexGuard 的许可证文件设置发生了变化。

我刚刚将 Android Studio 版本从 2.2.3 更新到 2.3,并将我的 Gradle 版本从 2.14.1 升级到 3.3。升级到 Gradle 3.3 版后,我收到了 OP 记录的相同错误:

Can't find a DexGuard license file.
You should place your license file dexguard-license.txt
1) in a location defined by the Java system property 'dexguard.license',
2) in a location defined by the OS environment variable 'DEXGUARD_LICENSE',
3) in your home directory, 
4) in the class path, or
5) in the same directory as the DexGuard jar.

我的 DexGuard 配置使用 Gradle 版本 2.14.1 和我的 dexguard-license.txt 文件在与 DexGuard jar 相同的目录中(建议 #5)。

事实证明,DexGuard 的文档说明如下:

Note: when using Gradle 3.1+, the license file will not be found anymore when placed in the same directory as the DexGuard plugin jar.

(来源:DexGuard 7.3.10 文档 -> 快速入门 -> 设置您的许可证文件)

我想将我的许可证文件保存在与 DexGuard jar 相同的目录中,因此我实施了建议 #1。我通过将以下行添加到我项目的 gradle.properties 文件来做到这一点:

systemProp.dexguard.license=./app/libs/Dexguard_7_3_10

请注意,我的 DexGaurd jar 和 dexguard-license.txt 文件位于以下目录中:{项目文件夹}/app/libs/DexGuard_7_3_10/

我选择了这个解决方案,因为我不仅在本地构建而且还在 Jenkins 上构建 CI。该解决方案使我不必在构建服务器本身上实施任何更改(即本地环境变量、将文件复制到服务器主目录或 class 路径选项)。我希望这可以帮助其他偶然发现此问题并发现错误消息令人困惑的人。

如果你有dexguard-license.txt那么你可以在build.gradle下定义它如下。

dexguard {

        version = '9.1.+'
  
        // Keep the license secure in your CD/CI
        **license = '/../YOURDIRECTORY/dexguard-license.txt'**
        configurations {
        release {
                ..
                ..
                
        }
        
    }