PhilipSa
PhilipSa

Reputation: 255

How do you combine multiple gradle flavors or exclude one?

flavorDimensions("color")

productFlavors {
    register("red") {
        setDimension("color")
    }
    register("blue") {
        setDimension("color")
    }
}

redImplementation("red library")
blueImplementation("blue library")

This generates the build variants: blueDebug, blueRelease, redDebug, redRelease

But in addition to these i want a build variant that is a combination of these two so the final list will be: blueDebug, blueRelease, redDebug, redRelease, blueRedDebug, blueRedRelease

If you have them in different flavordimensions you end up with just the blueRed combination.

How do i setup my gradle script to support this case? The end goal is to able to choose if you want just the red library, just the blue library or the combination of both.

Upvotes: 0

Views: 259

Answers (2)

Eugen Pechanec
Eugen Pechanec

Reputation: 38243

Since you already have the blue and red library modules, your app can have these flavors:

  • blue, which depends on blue library
  • red, which depends on red library
  • blueRed, which depends on blue and red libraries

I'm assuming that blue and red libraries can be included side by side.

flavorDimensions("color")

productFlavors {
    register("red") {
        setDimension("color")
    }
    register("blue") {
        setDimension("color")
    }
    register("blueRed") {
        setDimension("color")
    }
}

redImplementation("red library")
blueImplementation("blue library")
blueRedImplementation("red library")
blueRedImplementation("blue library")

Upvotes: 2

Biscuit
Biscuit

Reputation: 5257

I don't think this is possible with flavors. I can recommend you to read this article to know more about flavors.

And have a look at the doc

Upvotes: 0

Related Questions