Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom strings for debug buildType

Tags:

android

gradle

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: Android Studio Setup

-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...

like image 940
volkersfreunde Avatar asked Sep 25 '14 07:09

volkersfreunde


3 Answers

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"]
        }
    }
}
like image 56
volkersfreunde Avatar answered Nov 08 '22 23:11

volkersfreunde


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

like image 20
Paulo Abreu Avatar answered Nov 09 '22 01:11

Paulo Abreu


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'] 
like image 37
Gabriele Mariotti Avatar answered Nov 09 '22 01:11

Gabriele Mariotti