lukstei lukstei - 2 months ago 17
Android Question

Add dependency to specific productFlavor and buildType in gradle

I'm wondering how to add dependency to specific productFlavor and buildType in gradle.
For example I have productFlavor

and build type
, how can I add a dependency on the

I've tried many variants but neither works.

For example I tried:

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.


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:

Wait until the project is evaluated.

afterEvaluate {
    task yourTask(dependsOn: assembleFreeRelease) {
        println "Your task"

Lazily declaring the task dependency as String.

task yourTask(dependsOn: 'assembleFreeRelease') {
    println "Your task"