I have an android app and I want to change the app label for the debug and other buildTypes. I don´t have any flavors!
Here is the setup that I believe looks like it should work:
-src
|-debug
|-res
|-values
|-strings.xml
|-main
|-res
|-values
|-strings.xml
|-java
[...]
I have no custom sourcesets just a debug buildType:
buildTypes {
debug {
applicationIdSuffix ".debug"
}
}
so I though
sourceSets.debug.res.srcDirs = ['src/debug/res']
would to the trick. But it doesn't. Any ideas?
How to change app name per Gradle build type does not work anymore...
I found another sweet solution to this, using manifest placeholders:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="${applicationLabel}">
<activity
android:label="${applicationLabel}">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and in your gradle file:
android {
defaultConfig {
manifestPlaceholders = [ applicationLabel:"@string/app_name"]
}
buildTypes {
debug {
applicationIdSuffix ".debug"
manifestPlaceholders = [ applicationLabel:"MyApp Debug"]
}
}
}
buildTypes {
release {
resValue 'string', 'APP_NAME', '"My App Release"'
}
debug {
resValue 'string', 'APP_NAME', '"My App Debug"'
}
}
value\strings.xml
< string name="app_name" >@string/APP_NAME< /string>
and use app_name everywhere
You have to use
|-debug
|-res
|-values
|-strings.xml
In your picture you have debug/res/strings.xml
Also you doens't need it (because it is the standard, but the issue isn't here).
sourceSets.debug.res.srcDirs = ['src/debug/res']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With