Search code examples
androidgradleandroid-productflavors

Two dimensional product flavors, Android studio?


In my game I have the two different configurations: 1- Characters 2-Markets. Each character represents a cartoon character and each market represents a local market to use their billing/advertising capabilities.

I have 20 characters and 4 markets. Both characters and markets need their own set of configuration in code and xml files.

The method I have implemented to manage this situation is to use one flavor per character per market in my app-level build.gradle:

productFlavors {
    character1_market1 {flavorDimensions "in_1"}
    character1_market2 {flavorDimensions "in_2"}
    character1_market3 {flavorDimensions "in_3"}
    character1_market3 {flavorDimensions "in_3"}
    ...
    charactern_market1 {flavorDimensions "in_65"}
    charactern_market2 {flavorDimensions "in_66"}
    charactern_market3 {flavorDimensions "in_67"}
    charactern_market4 {flavorDimensions "in_68"}
}

Which clearly adds a lot of boilerplate code and resource to manage. For example for each set of characters I need a custom drawable folder. But now the same drawable folder of each character is going to be repeated for each market variation (4 times). Or I need a custom AndroidManifest.xml file for each market (4 different manifest files). But now I have to repeat these AndroidManifest.xml files for each character-market flavor.

How can I manage this in a more efficient way so I can have different set of market configurations and character configurations without having repeated code and resource? The ultimate result I want to reach is at release time, when I choose a flavor concerning a specific character and a specific market, the configuration for each is applied automatically.


Solution

  • You can create different dimension file for each flavor

    For Example if you have flavor flavor_a, flavor_b

    Create folder inside src folder with flavor name.You already having main folder(it's should contain common files) and you should follow same folder names inside folder flavor_a and flavor_b

    dimension path for flavor_a is app/src/flavor_a/res/values/dimens.xml dimension path for flavor_b is app/src/flavor_b/res/values/dimens.xml

    You can follow for all resources for your flavors.