In an Android gradle build, change contents of strings.xml during build
I would like to be able to load the value of user-visible strings from res/values/strings.xml from our CMS (or some DB), during the gradle build.
<string name="button_label">OK, do it</string>
Could be changed to
<string name="button_label">OK, do it now!</string>
... or whatever.
The idea being that the new value would be read AT BUILD TIME from our CMS, and then would get baked into the APK file. ( The motivation is to automate changes to app strings, so that any text from the app would be read from an existing CMS).
What's the best way to achieve this? Is it possible to generate/modify the resource files (e.g. strings.xml ) during build, just before they are used by the Android build system?
Here's a solution where your strings are modified via an external propertise file. Not sure that this fits your requirement exactly, but it should get you off to a start.
I do something similar in my builds - I have some custom gradle tasks with this type of replacement called inside of their doFirst(). The regex here could probably use some polishing, and the input format may change per your requirement, but in a few local tests this seems to work for me.