2

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.

Leos Literak
  • 8,805
  • 19
  • 81
  • 156
  • you made a values directory for a custom location. So you have to make the same directory in debug also to make it work. See my answer. – Bhuvanesh BS Aug 25 '17 at 19:16

1 Answers1

2

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:)

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
  • Yes it work but why? Why is there no fallback to values directory within debug build variant? – Leos Literak Aug 26 '17 at 07:26
  • If you have multiple variants like debug, release or flavors, build tool first check for the specific variant items. If the resource not available for specific variant then it will take that from main. In your case, you are using region specific values directory(values-cs) so the build tool first checks the debug directory for the file. if it is not available then it will take that from the main directory. – Bhuvanesh BS Aug 26 '17 at 07:48
  • I would expect that if cs in debug is not defined, it will look up default string in debug. And if not found then it would use main. – Leos Literak Aug 26 '17 at 16:52
  • Unfortunately the build system not designed like that. It will always look for main resource. There is no way to tell the build system to do that. – Bhuvanesh BS Aug 26 '17 at 17:50