我需要根据使用的产品风格创建不同的应用程序名称.
虽然通过简单地设置字符串资源很容易,但我不能再这样做,因为当应用程序上传到hockeyapp时,应用程序名称设置为“@ string / app_name”而不是app_name的值.
通过将清单中的标签设置为“${applicationName}”并使用设置值,我取得了一些进展
manifestPlaceholders = [ applicationName : appName ];
在产品flavor块中,以便在编译时设置该值.
当我尝试将构建类型附加到应用程序名称时出现问题.我似乎无法找到一种方法来了解当前在产品风格中使用的构建类型.
这是用于可读性的构建的精简版本
android {
buildVersionName "1.0.0
buildTypes {
release {
... nothing special
}
uat {
signingConfig signingConfigs.debug
buildType = "uat"
applicationIdSuffix = "." + buildType
}
debug {
signingConfig signingConfigs.debug
buildType = "uat"
applicationIdSuffix = "." + buildType
}
}
productFlavors{
flavor1{
def appName = "app name " + buildType;
manifestPlaceholders = [ applicationName : appName ];
applicationId [id]
def clientIteration = [client iteration]
versionName buildVersionName + clientIteration
versionCode [version code]
}
flavor2{
... same as above with different app name
}
flavor3{
... same as above with different app name
}
}
}
此代码工作正常,但变量’buildType’始终是最后一个构建类型(在本例中为debug),这意味着应用程序名称总是在末尾进行调试.
可能值得注意的是,我不需要在应用程序名称的末尾附加任何附加内容.
解决方法:
我知道我有点迟到了,但如果你想要根据口味不同的名字,你应该有这样的东西:
productFlavors{
flavour 1 {
applicationId "your_app_id"
resValue "string", "app_name", "Flavour 1 app name"
.......
}
flavour 2 {
applicationId "your_app_id"
resValue "string", "app_name", "Flavour 2 app name"
.......
}
}
在AndroidManifest.xml中:
android:label="@string/app_name"
希望这可以帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。