问题描述
我有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!
这篇关于对于不同的构建口味不同的应用程序的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!