Search code examples
androidkotlingradlegradle-dependencies

How to select different aar based on buildTypes


I have an android app which is using an aar lib. the lib is stored in the libs folder. it's working fine but however I found a debug version of the lib so I would like to be able to select between the libs. So I defined first the libs as below:

publishing {
    publications {
        libLogLatest(MavenPublication) {
            groupId 'com-log'
            artifactId 'libLog'
            version '0.1.0'
            artifact("$libsDirName/libLog_0_1_0.aar")
        }
        libLogDbg(MavenPublication) {
            groupId 'com-log'
            artifactId 'libLogDbg'
            version '0.1.0'
            artifact("$libsDirName/libLog_0_1_0_Int.aar")
        }
    }
}

Then I load it in the dependencies section:

dependencies {
    implementation "com-log:libLog:0.1.0"
    //implementation "com-log:libLogDbg:0.1.0"
}

Is there a way to automatically select between libLog and libLogDbg using the buildType?


Solution

  • We have such configuration in dependencies block for app module like this:

        DebugImplementation(files('libs/library-debug.aar'))
        ReleaseImplementation(files('libs/library-release.aar'))