Change string resource by flavor / debug-build

Yes you can do that inside your app gradle under buildTypes..

 buildTypes {
        mybuild {
                 resValue "string", "test_some_card_text", '"test"'
                 resValue "string", "other_text", '"other"'
                }
         debug {
                 resValue "string", "test_some_card_text", '"test"'
                 resValue "string", "other_text", '"other"'
              }
          }

Then access it like this.

getApplicationContext().getResources().getString(R.string.test_some_card_text);
getApplicationContext().getResources().getString(R.string.other_text);

For build you need to select that build variants and have to build it.


It is not possible to change the string value after creation of the apk. But you can assing the value to text or edittext ... etx dynamically after creation of the apk.


As @Aditya Naik said it is possible using Flavors. Official doc says

BuildType -> Flavor -> main -> Dependencies.

This means that if a resource is declared in both the Build Type and in main, the one from Build Type will be selected.

Note that for the scope of the merging, resources of the same (type, name) but different qualifiers are handled separately.

This means that if src/main/res has

  • res/layout/foo.xml
  • res/layout-land/foo.xml

    and src/debug/res has

  • res/layout/foo.xml

    Then the merged resource folder will contain the default foo.xml from src/debug/res but the landscape version from src/main/res

for more info visit Official doc - Resource Merging


Yes, Gradle lets you override strings.

  • Add this inside buildTypes{} in your app/build.gradle

    debug { applicationIdSuffix "debug" }

  • That should create a directory titled debug next to main. If not then manually create one. (Seriously, I haven't tried this, but I know this is possible.)

  • Then if your strings_test.xml is under res/values, create similar directory structure under debug/ and put your strings_text.xml with debug specific strings there. This will show up in your debug build. The ones under release/main/res/values will show up in your release build.

PS: You can override all res and asset data like this according to buildTypes and flavor. You can't override Java files though, you could however add them.