Build variants in Gradle for a Library Project in Android

It’s a @bifmadei answer from google code issue and it helps for me:

Obsolete 1:
Try setting this in the dependency project

android {
    publishNonDefault true
    ...
}

Obsolete 2: Starting from gradle 4.10.1 publishNonDefault is true by default. So just use the recommendation below:

Include this in the project that uses it

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

Taken from here: https://code.google.com/p/android/issues/detail?id=66805

Note that with implementation instruction separated releaseCompile and debugCompile become obsolete: https://stackoverflow.com/a/44364851/3379437

Update:

Approach from the previous step still can be used with a custom build configuration:

implementation project(path: ':theotherproject', configuration: 'staging')

Leave a Comment