Search code examples
androidandroid-buildandroid-build-flavors

String resource from debug variant does not work


I used to have defined an application name as a resource in the 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'
    }
 }

Then I found a need for a localization, so I deleted all resValue from the gradle and defined in in 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>

When I compile my application in Studio, it displays Leli Matematika. I expected LeliMath DEV. I was inspired by this answer https://stackoverflow.com/a/37579475/1639556.


Solution

  • You will get it by placing the string here.

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

    Hope it helps:)