TootsieRockNRoll
TootsieRockNRoll

Reputation: 3288

Android flavor+build type specific dependencies

I have flavours in my build.gradle file, staging, stable and production, as well as the default build types debug and release. I have different AAR files for each and every one of these, for example I have an AAR that I want to use for stagingDebug, a different one for stagingRelease, as well as stableDebug and all other variants.

I am able to use releaseImplementation ('xxxx@aar') and stagingImplementation ('yyyy@aar'), but I'm not able to use stagingReleaseImplementation ('zzzzz@aar')

Is there any way I can use flavor+build type specific dependencies?

Upvotes: 1

Views: 185

Answers (1)

matdev
matdev

Reputation: 4283

A solution is to define a variable in your top level build.gradle file:

project.ext.BuildCmdLine = "Release"

android {
    applicationVariants.all { variant ->
        project.ext.BuildCmdLine= variant.buildType.name // Sets the current build type
    }
}

Then in your module's build.gradle files, you can set the dependencies you want to use based on project.ext.BuildCmdLine:

dependencies {

    if (project.BuildCmdLine == "Release") {
        api(name: 'yourlib-release', ext: 'aar')
    } else {
        api(name: 'yourlib-debug', ext: 'aar')
    }
}

Upvotes: 1

Related Questions