How can I add flavors in a module with Android Studio?

In the library module’s build.gradle, you need a couple extra lines to tell it to export the flavors and which build variant to use by default if not specified when being included from another module:

android {
    defaultPublishConfig "productionRelease"
    publishNonDefault true

    productFlavors {
        alpha {
        }
        production {
        }
    }
}

That publishNonDefault bit is only necessary if someone would want to depend on something other than the productionRelease variant. Presumably this is the case if you set up multi-flavors in your library in the first place.

Now if you add a dependency from another module via this in its build.gradle:

dependencies {
    compile project(':module')
}

it will depend on the productionRelease variant by default. If you’d like to depend on a non-default variant:

dependencies {
    compile project(path: ':module', configuration:'alphaDebug')
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)