【问题标题】:Android Gradle Plugin 7.2 ignores added proguard file in Android App build processAndroid Gradle Plugin 7.2 忽略 Android App 构建过程中添加的 proguard 文件
【发布时间】:2022-06-16 21:48:01
【问题描述】:

我有一个为 Android 应用程序项目编写的 Gradle 插件。除其他外 - 此插件将自定义 ProGuard 规则文件添加到所有正在构建的 ApplicationVariants。

在引入 Android Gradle 插件 7.2 之前一直运行良好。自从我开始使用 AGP 7.2 编译我的应用程序 - 插件添加的 ProGuard 文件被忽略.

Code:

    project.android.buildTypes[<variant.buildType.name>].proguardFile = new File(<custom Proguard rules file path>)

这在 AGP <= 7.0 中有效,没有任何问题。构建过程的日志中没有异常。

我尝试了另一种方法并得到了相同的结果:我尝试使用脚本添加 ProGuard 文件(根本不使用插件) - 但结果是一样的 -此文件被忽略. 这是我在 build.gradle 添加的代码:

afterEvaluate {
    for (def buildType : project.android.buildTypes) {
       buildType.proguardFile file(< full path>)
    }
}

有任何想法吗?

【问题讨论】:

标签: android gradle android-gradle-plugin proguard


【解决方案1】:

在 Groovy 中,可以为 android.defaultConfig 设置值:

// this sets one file
android.defaultConfig { config ->
    proguardFile new File("../general.pro")
}

// this adds an additional file
android.defaultConfig { config ->
    proguardFiles.add(new File("../general.pro"))
}

// proof of concept
android.buildTypes { buildType ->
    println buildType
}

这发生在:prepareKotlinBuildScriptModel 之前,这意味着早期。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-12
    • 2016-06-19
    • 2015-07-24
    • 2020-12-17
    • 2017-03-04
    • 1970-01-01
    • 2013-11-02
    • 2017-02-01
    相关资源
    最近更新 更多