添加依赖于特定productFlavor和buildType的摇篮 [英] Add dependency to specific productFlavor and buildType in gradle
问题描述
我不知道如何添加依赖于特定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:
等待,直到<一href="http://www.gradle.org/docs/current/javadoc/org/gradle/api/Project.html#afterEvaluate%28groovy.lang.Closure%29">project评估。的
afterEvaluate {
task yourTask(dependsOn: assembleFreeRelease) {
println "Your task"
}
}
<一个href="http://www.gradle.org/docs/current/userguide/userguide_single.html#sec%3atask_dependencies">Lazily声明任务依赖为String。的
Lazily declaring the task dependency as String.
task yourTask(dependsOn: 'assembleFreeRelease') {
println "Your task"
}
这篇关于添加依赖于特定productFlavor和buildType的摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!