Different app names for different build flavors?

前端 未结 9 1721
-上瘾入骨i
-上瘾入骨i 2020-12-07 11:07

I have 2 build flavors, say, flavor1 and flavor2.

I would like my application to be named, say, \"AppFlavor1\" when I build for flavor1 an

9条回答
  •  无人及你
    2020-12-07 11:26

    Instead of changing your main strings.xml with a script and risk messing up your source control, why not rely on the standard merging behavior of the Android Gradle build?

    My build.gradle contains

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    
        release {
            res.srcDir 'variants/release/res'
        }
    
        debug {
            res.srcDir 'variants/debug/res'
        }
    }
    

    So now I can define my app_name string in the variants/[release|debug]/res/strings.xml. And anything else I want to change, too!

提交回复
热议问题