0

I'd like to have different configurations for debug and release versions. For the most part, By configuration I mean having different string constants,

e.g. connection strings. Additionally I'd like to have a running configuration to be connected to a build configuration, so that when I select 'release' from the running dropdown, the correct version is automatically built. Is that even possible? Is there a way to use a different string resource file based on build configuration?

PriyankaChauhan
  • 953
  • 11
  • 26
eko
  • 369
  • 4
  • 15
  • yes you can define different string files for debug and release.Create `release` folder. Refer [this](http://stackoverflow.com/a/36042309/6005977) – Ankita Shah Nov 29 '16 at 06:57

2 Answers2

3

There is a product flavors functionality available in android studio. You have to add different flavors for your application in the app level build.gradle file. You can set them as follows:

  productFlavors {
    sandbox {
        versionCode 1
        versionName "1.0"
        applicationId "com.abc.sandbox"
        buildConfigField 'String', 'HOST', '"http://api/v1/"'
    }

    development {
        versionCode 1
        versionName "1.0"
        applicationId "com.abc.development"
        buildConfigField 'String', 'HOST', '"http://api/v1/"'
    }

    production {
        versionCode 1
        versionName "1.0"
        applicationId "com.abc.production"
        buildConfigField 'String', 'HOST', '"http://api/v1/"'
    }

}

You can run respective flavor by selecting it from build versions before running your application.

Prashant Sable
  • 1,003
  • 7
  • 19
  • Thanks! I didn't know about buildConfigField, that's exactly what I was looking for. – eko Nov 29 '16 at 07:38
0

You can create a separate strings.xml for debug mode and add your strings to it.

  1. Right click res folder in your projects direcotry -> new -> Android Resource File.
  2. In the new window, Enter filename (strings.xml or any other file you need), select debug in Source Set as shown in image, click OK.
  3. Add your required data here in this new file as,
    <string name="same_key_as_in_original">Value</string>

enter image description here