android - 调试变体中的字符串资源不起作用

标签 android android-build android-build-flavors

我曾经在 gradle 中将应用程序名称定义为资源:

android {
 compileSdkVersion 26
 buildToolsVersion '26.0.1'
 defaultConfig {
    applicationId "lelisoft.com.lelimath"
    resValue 'string', 'app_name', 'LeliMath'
 }
 buildTypes {
    debug {
        applicationIdSuffix ".debug"
        resValue 'string', 'app_name', 'LeliMath DEV'
    }
 }

然后我发现需要本地化,所以我从 gradle 中删除了所有 resValue 并在 strings.xml 中定义:

app\src\debug\res\values\strings.xml
<string name="app_name">LeliMath DEV</string>

app\src\main\res\values\strings.xml
<string name="app_name">Leli Math</string>

app\src\main\res\values-cs\strings.xml
<string name="app_name">Leli Matematika</string>

当我在 Studio 中编译应用程序时,它显示 Leli Matematika。我期待 LeliMath DEV。我受到这个答案的启发https://stackoverflow.com/a/37579475/1639556 .

最佳答案

您可以通过将字符串放在这里来获取它。

app\src\debug\res\values-cs\strings.xml
<string name="app_name">LeliMath DEV</string>

希望有帮助:)

关于android - 调试变体中的字符串资源不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45887587/

相关文章:

android - SQLiteException 当联系人有照片时无法将 BLOB 转换为字符串。安卓

flutter - 5 月 1 日之后,我们将如何处理 jcenter() 存储库,它有什么替代方案?

Android Tools r20 不会使用 ant 使用库项目构建项目,说我在库中缺少 project.properties 但我没有

java - Android 中使用 GoogleAPI 进行音译

android - GPS 让我只有一个位置,而且永远不会改变 Android

android - 如何将 Gradle 依赖项更新到最新版本

android - 如何在Build-Tools 3.6.0中使用 “R.id object = new R.id();”?

android - 为什么发布构建抛出错误,但在 buildTypes 相同时不进行调试? (Android gradle 构建类型)

android - 用于仅测试依赖项的 Gradle 变体感知依赖项管理

android - MediaScannerConnection scanFile 扫描器崩溃