Home > database >  Gradle dependencies based on multi flavorDimensions
Gradle dependencies based on multi flavorDimensions

Time:11-13

I have the following flavours configuration in an Android project:

android {
    buildTypes {
        release { }
        debug { }
    }

    flavorDimensions "fruit", "color" 

    productFlavors {
        apple { 
            dimension "fruit"
        }
        peach { 
            dimension "fruit"
        }
        banana {
            dimension "fruit"
        }

        red {
            dimension "color" 
        }
        green {
            dimension "color" 
        }
        yellow {
            dimension "color" 
        }
    }
}


dependencies {
    appleRedImplementation 'com.apple:color_red:1.1.0'
    appleGreenImplementation 'com.apple:color_green:1.1.0'
    appleYellowImplementation 'com.apple:color_yellow:1.1.0'
    // No dependency for other fruit build type 
}

I need to keep the com.apple:color_*:1.1.0 dependency only for the apple flavorDimensions builds, but change it based on the color flavorDimensions builds?

CodePudding user response:

If you want to add dependencies to specific configurations of multiple build flavor dimensions, you need to define those combinations first:

android{
    ...
    productFlavors {
        ...
    }
    configurations {
        appleRedImplementation {}
        appleGreenImplementation {}
        appleYellowImplementation {}
    }
}

This answer here references this as well: https://stackoverflow.com/a/60776044/2258611

  • Related