对于不同的构建口味不同的应用程序的名称?不同、应用程序、口味、名称

2023-09-06 03:06:53 作者:Vampire(吸血鬼)

我有2个版本的口味,比如, flavor1 和 flavor2 的。

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

我想我的应用程序被命名,比如 AppFlavor1 的当我构建flavor1和 AppFlavor2 的当我建立的风味2

I would like my application to be named, say, "AppFlavor1" when I build for flavor1 and "AppFlavor2" when I build for flavor 2.

这不是活动我想更改标题。我想改变应用程序的名称,因为它是显示在手机菜单上和其他地方。

It is not the title of activities I want to change. I want to change the app name as it's displayed on the phone menu and elsewhere.

build.gradle 我可以设置各种参数,我的口味,但是,现在看来,没有应用程序标签。我不能改变编程基于一些变量的应用程序标签了。

From build.gradle I can set various parameters for my flavors but, it seems, not the app label. And I can not change the app label programmatically based on some variable, too.

那么,人们怎样处理呢?

So, how do people handle this?

推荐答案

而不是改变你的主要的strings.xml与脚本和风险搞乱了你的源代码控制,为什么不依靠Android的摇篮打造的标准合并行为?

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?

我的 build.gradle 包含

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'
    }
}

所以,现在我可以定义我在 APP_NAME 字符串变种/ [发布|调试] /res/strings.xml 。和其他任何我想改变,太!

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!