在 gradle 中添加对特定 productFlavor 和 buildType 的依赖 [英] Add dependency to specific productFlavor and buildType in gradle
问题描述
我想知道如何在 gradle 中添加对特定 productFlavor 和 buildType 的依赖.例如,我有 productFlavor free
和构建类型 release
,如何添加对 assembleFreeRelease
任务的依赖?
I'm wondering how to add dependency to specific productFlavor and buildType in gradle.
For example I have productFlavor free
and build type release
, how can I add a dependency on the assembleFreeRelease
task?
我尝试了很多变体,但都不起作用.
I've tried many variants but neither works.
例如我试过:
task('release', dependsOn: assembleProductionRelease) {
}
// error: Could not find property 'assembleProductionRelease' on root project 'app'.
或者:
task('release', dependsOn: 'assembleProductionRelease') {
}
这里没有错误,但是任务是针对每种风格和构建类型执行的,非常混乱.
Here there is no error but the task is executed for every flavor and build type, very confusing.
推荐答案
这些任务是根据您的 Android 插件配置动态生成的.在配置时,您还无法使用它们.您可以通过两种方式推迟任务的创建:
These task are generated dynamically based on your Android plugin configuration. At the time of configuration they are not available to you yet. You can defer the creation of your task in two ways:
等到 评估项目.
afterEvaluate {
task yourTask(dependsOn: assembleFreeRelease) {
println "Your task"
}
}
懒惰地声明任务依赖作为字符串.
Lazily declaring the task dependency as String.
task yourTask(dependsOn: 'assembleFreeRelease') {
println "Your task"
}
这篇关于在 gradle 中添加对特定 productFlavor 和 buildType 的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!