添加依赖于特定productFlavor和buildType的摇篮 [英] Add dependency to specific productFlavor and buildType in gradle

查看:516
本文介绍了添加依赖于特定productFlavor和buildType的摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何添加依赖于特定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.

推荐答案

这些任务都是动态生成基于你的Andr​​oid插件配置。在配置的时候,他们都没有提供给你呢。您可以推迟创建你的任务的方法有两种:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆