Search code examples
androidandroid-productflavors

Using different icon for different flavor dimension


I have created two flavors and two dimensions for an Android application. The flavors are free and premium and the dimensions are default and withExtras. What I want to have is the following flavors:

freeDefault
|---freeWithExtras

premiumDefault
|---premiumWithExtras

The withExtras dimensions should be based on the default flavors but add some more functionality. I would also like to have a different icon for the freeWithExtras version. I have created a different icon and placed it in the src/withExtras/res/drawable folder. The other (default) icon is in the src/free/res/drawable folder. When I run the freeWithExtras dimension, the icon being used is that from the free/res/drawable folder. How can I make the above dimension use the image that is placed in its res folder? Is there something wrong with my setup?


Solution

  • I'm assuming your flavor / dimension setup looks like this:

    flavorDimensions "mode", "extras"
    ...
    productFlavors {
        free {
          dimension "mode"
        }
    
        premium {
          dimension "mode"
        }
    
        default {
          dimension "extras"
        }
    
        withExtras {
          dimension "extras"
        }
    }
    

    You should be able to create a source folder for your specific build variant freeWithExtras which combines two flavors. Then you can and place your icon into src/freeWithExtras/res. The order you specify your flavorDimensions controls the order in which the flavors are concatenated to build the folder / build variant name.