Let's say we have strings_test.xml, which stores string values for testing and should be shown in a debug-release. When the apk gets build as a release version all values should be change to an empty string e.g. <string name="test_some_card_text">@string/empty</string>
.
Is there a possibility to achieve this?
As always, thanks in advance.
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 tomain
. 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 underres/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.
For those who come here looking for some way to apply a similar method to
raw
resources, I dealt with it usingbuildConfigField
.Pay attention to the quotes. After that, place
BuildConfig.shared_resource_name
in the files whereverR.raw.resource_value
used to be accessed directly.This can be used to other resources I think.
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
for more info visit Official doc - Resource Merging
Yes you can do that inside your app gradle under buildTypes..
Then access it like this.
For build you need to select that
build variants
and have to build it.