Forget the string.xml files. Everything can be easily configured in build.gradle.
First of all, you must save the line pointer "app_name" in the AndroidManifest file and delete all instances of "app_name" in the resource string files:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:label="@string/app_name"> <activity android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Secondly, the value of the resource @ string / app_name is currently undefined. Therefore, we must apply our default definition in the build.gradle file:
defaultConfig { applicationId "com.example.myapp" minSdkVersion 14 targetSdkVersion 22 versionCode 123423432 versionName "1.0.0" resValue 'string', 'app_name', '"My app label"' }
Currently, app_name is defined for all build types. Assuming you want to change the application label for buildTypes , each type of assembly should be defined with a string value in the same build.gradle branch:
buildTypes { release { resValue 'string', 'app_name', '"My app label Release"' } debug { resValue 'string', 'app_name', '"My app label Debug"' } }
Since this resource value is set programmatically, we also need to add certain translations of lint ignore in the case of Release :
lintOptions { disable 'MissingTranslation' }
If you want to modify it accordingly using a set of defined Flavors (dev, qua or prd), add resValues definitions to productFlavours instead of buildTypes:
productFlavors { dev { applicationId "com.example.myapp.dev" resValue 'string', 'app_name', '"My app label Dev"' } qua { applicationId "com.example.myapp.qua" resValue 'string', 'app_name', '"My app label Qua"' } prd { applicationId "com.example.myapp.prd" resValue 'string', 'app_name', '"My app label Prd"' } }