Android Configuring settings.gradle for different app flavours

27 views Asked by At

How can I configure settings.gradle to accommodate different setups based on the flavours of my app?

In my settings.gradle, I have several modules defined, such as:

include ':SubModule1'
include ':SubModule2'
.....
include ':SubModule8'
include ':SubModule10'

Now, I have two flavour dimensions defined: marketOne and marketTwo. Depending on the market, I would like settings.gradle to distinguish between the two markets, for example:

include ':SubModule1'
if(selectedMarket == marketOne) {
    include ':SubModule2'
}

.....
if(selectedMarket == marketTwo) {
    include ':SubModule8'
}
include ':SubModule10'

Essentially, I need to set the market or some sort of flag in selectedMarket. However, I'm encountering difficulties obtaining the current buildVariant selected in Android Studio during Gradle sync and build.

Do you have any suggestions on how to accomplish this?

1

There are 1 answers

0
Lino On BEST ANSWER

I believe settings.gradle file is not meant to do what you're looking for. You can include all the submodules in the settings.gradle file and then link as dependency the module you need in the app's build.gradle file, dependencies section:

dependencies {
   ...
   marketOneImplementation(project(":SubModule2"))
   marketTwoImplementation(project(":SubModule8"))
}

In this way, when the marketOne flavor is selected then submodule 2 will be included (but not submodule 8). Same thing when the marketTwo flavor is selected.