前体:我想本地化应用程序名(使用字符串资源)
同时从gradle文件中添加build类型后缀(“调试”)。
在这里,我试图连接字符串资源"app_name“和gradle变量"AppNameSuffix”
预期应用程序名称: 关于产品风味"all“-”我的应用程序调试“ 产品风味“中国”-“我的中文应用程序调试” 以及后面的生成类型以"RELEASE“和"CANARY”后缀。
build.gradle:
buildTypes {
debug {
manifestPlaceholders = [AppNameSuffix: "DEBUG"]
...
}
release{
manifestPlaceholders = [AppNameSuffix: "RELEASE"]
...
}
canary{
manifestPlaceholders = [AppNameSuffix: "CANARY"]
}
}
productFlavors {
china {
applicationId "com.myapplication.china"
}
all {
//default
applicationId "com.myapplication.all"
}
}清单:
<application
...
android:label="@{@string/app_name(${AppNameSuffix})}">
...
</application>计算gradle变量时在"$“符号处的错误
main/res/string.xml .xml:
<string name="app_name">My application %s</string>中国/res/string.xml.xml:
<string name="app_name">My Chinese application %s</string>参考文献:
发布于 2020-11-13 09:13:12
在gradle文件中,使用小写,以便资源名称有效:
buildTypes {
debug {
manifestPlaceholders = [AppNameSuffix: "_debug"]
...
}
release{
manifestPlaceholders = [AppNameSuffix: "_release"]
...
}
canary{
manifestPlaceholders = [AppNameSuffix: "_canary"]
}
}修改您的清单:有括号要删除,或者工具:replace以添加(如果还没有添加):
<application
...
android:label="@string/app_name${AppNameSuffix}"
tools:replace="android:label"
...
</application>然后,需要添加与后缀匹配的字符串资源:
<string name="app_name">My application</string>
<string name="app_name_debug">My application DEBUG</string>
<string name="app_name_release">My application RELEASE</string>
<string name="app_name_canary">My application CANARY</string>您还可以使用风味,并将特定的strings.xml文件放在与您的口味相匹配的文件夹中。
https://stackoverflow.com/questions/54911292
复制相似问题