androidandroid-productflavorsandroid-flavors

Cleaning flavor paths for different build types


I have about 8 flavours in my app, plus the default main flavour. I want to have a different icon for each flavor but also a different icon for each build, eg debug, demo, release.

The folder structure, I believe, means I have to create mutliple folders as follows:

main
    -res
        -mipmap
flavor1
    -res
        -mipmap
flavor1Debug
    -res
        -mipmap
flavor1Demo
    -res
        -mipmap
flavor2
    -res
        -mipmap
flavor2Debug
    -res
        -mipmap
flavor2Demo
    -res
        -mipmap

But I want:

main
    -res
        -mipmap
flavor1
    -debug
        -res
            -mipmap
    -demo
        -res
            -mipmap
    -production
        -res
            -mipmap
flavor2
    -debug
        -res
            -mipmap
    -demo
        -res
            -mipmap
    -production
        -res
            -mipmap

This is so I have each flavors assets inside one folder per flavor, instead of creating multiple folders for each flavor + build.

Is this possible? I thought it worked like this as standard, but maybe I need to change my sourceSets?

Thanks.


Solution

  • OK so I achieved this by just using sourceSets, eg:

    sourceSets {
            main { res.srcDirs += ['src/main/res'] }
    
            flavour1 {res.srcDirs += ['src/flavour1/main/res']}
            flavour1Dev { res.srcDirs += ['src/flavour1/dev/res'] }
            flavour1Demo { res.srcDirs += ['src/flavour1/demo/res'] }
    
            flavour2 { res.srcDirs += ['src/flavour2/main/res'] }
            flavour2Dev { res.srcDirs += ['src/flavour2/dev/res'] }
            flavour2Demo { res.srcDirs += ['src/flavour2/demo/res'] }
    }