Change string value in config file based on build type - Android

1.2k Views Asked by At

I have a config file (config.xml) in res/values location. Inside this file, I need to add a string resource, where its value should change based on build type (debug/release).

It's not possible to create multiple files like res/debug/values/config.xml and res/release/values/config.xml. I am looking for a solution like the manifest place holder, where I can able to configure value in the Gradle and use it in config.xml

1

There are 1 best solutions below

0
On

You can Write resource for different builds, write this in your build.gridle file and in android tag

buildTypes {
    release {
       debuggable false
        minifyEnabled true
        shrinkResources true
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 
'proguard-rules.pro'
      // for release build
        resValue "string", "string_name_1", '" your string value "'
        resValue "string","string_name_2",'"your string name 2"'

    }

    debug {
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 
 'proguard-rules.pro'

           // for debug build 
        resValue "string", "string_name_1", '" your string value "'
        resValue "string","string_name_2",'"your string name 2"'
    }
 }