Android Studio Gradle – set module build variant

An update over Marcus answer:

I don’t know since what version of Gradle /Android Studio, but now it’s possible to do:

Update: publishNonDefault is now deprecated and not needed anymore. Just use the config further below.

###Library’s build.gradle:

android {
    ...
    publishNonDefault true
}

App’s build.gradle:

dependencies {
    debugCompile project(path: ':baseApp', configuration: 'debug')
    releaseCompile project(path: ':baseApp', configuration: 'release')
}

Changing the build variant of one of them in the Android Studio will change the build variant of the other.

At the moment the Gradle toolchain only builds libraries in the release variant by default, regardless of what you choose as your application build type. There are some suggested work arounds to that problem but they are mostly involved in your build configuration rather than anything with the dependency include.

The closest example I can think that is to what you want is to do the following;

dependencies {
    flavor1Compile project(path: ':lib1', configuration: 'flavor1Release')
    flavor2Compile project(path: ':lib1', configuration: 'flavor2Release')
}

But this is achieved through build flavours rather than build variants.

Leave a Comment