How to provide different Android app icons for different gradle buildTypes?

后端 未结 5 1077
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 19:12

I have two build types set in my gradle file: debug and release. I\'d like to be able to set a different app icon for the debug build

5条回答
  •  北海茫月
    2020-11-29 19:54

    For getting different icons while using different flavors with multiple dimensions, such as:

    flavorDimensions "color", "size"
    productFlavors {
        black {
            dimension "color"
        }
        white {
            dimension "color"
        }
    
        big {
            dimension "size"
        }
        small {
            dimension "size"
        }
    }
    

    This can be achieved as:

    First, put the debug resources in separate folders, such as:

    src/blackDebug/res
    src/whiteDebug/res
    

    Second, put the key with multiple flavor dimensions is that the sourceset name must contain all the possible flavor combinations, even if some of these dimensions do not affect the icon.

    sourceSets {
        // Override the icons in debug mode
        blackBigDebug.res.srcDir 'src/blackDebug/res'
        blackSmallDebug.res.srcDir 'src/blackDebug/res'
        whiteBigDebug.res.srcDir 'src/whiteDebug/res'
        whiteSamllDebug.res.srcDir 'src/whiteDebug/res'
    }
    

    Just to make it clear, the following will not work when multiple dimensions are in use:

    sourceSets {
        // Override the icons in debug mode
        blackDebug.res.srcDir 'src/blackDebug/res'
        whiteDebug.res.srcDir 'src/whiteDebug/res'
    }
    

提交回复
热议问题