app モジュールの flavor が staging なら api モジュールの staging flavor を使い、
app モジュールの flavor が production なら api モジュールの production flavor を使いたい。
この場合、build.gradle に次のような設定を行う。
api モジュールの build.gradle
- apply plugin: 'com.android.library'
- configurations {
- stagingDebugCompile
- stagingReleaseCompile
- productionDebugCompile
- productionReleaseCompile
- }
- android {
- ...
- publishNonDefault true
- productFlavors {
- production {
- ...
- }
- staging {
- ...
- }
- }
- }
app モジュールの build.gradle
- apply plugin: 'com.android.application'
- configurations {
- stagingDebugCompile
- stagingReleaseCompile
- productionDebugCompile
- productionReleaseCompile
- }
- android {
- ...
- productFlavors {
- production {
- ...
- }
- staging {
- ...
- }
- }
- }
- dependencies {
- ...
- stagingDebugCompile project(path: ':api', configuration: 'stagingDebug')
- stagingReleaseCompile project(path: ':api', configuration: 'stagingRelease')
- productionDebugCompile project(path: ':api', configuration: 'productionDebug')
- productionReleaseCompile project(path: ':api', configuration: 'productionRelease')
- }