我不知道如何添加依赖于特定productFlavor和buildType的摇篮。
比如我有productFlavor 免费
和建立键入发布
,我怎么能添加一个依赖于 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:
等待,直到project评估。的
afterEvaluate {
task yourTask(dependsOn: assembleFreeRelease) {
println "Your task"
}
}
Lazily声明任务依赖为String。的
Lazily declaring the task dependency as String.
task yourTask(dependsOn: 'assembleFreeRelease') {
println "Your task"
}