I have situation where I have multiple flavors of my app. For ex. Dev, Stage, Production flavors.
So, dev will be pointing to dev server url, dev app id etc. and same for stage and production. For app id which are present in my strings.xml, I can replace them using following code -
variant.mergeResources.doLast {
File valuesFile = file("${buildDir}/res/all/${variant.dirName}/values/values.xml")
println("Replacing app id in " + variant.dirName)
String content = valuesFile.getText('UTF-8')
def appid;
String variantDirName = variant.dirName;
if (variantDirName.contains("dev")) {
appid = '1234_dev'
} else if(variantDirName.contains("stage")) {
appid = '1234_stage'
} else if(variantDirName.contains("prod")) {
appid = '1234_prod'
} else {
appid = '1234_unknown'
}
content = content.replaceAll(/some_app_id/, appid)
valuesFile.write(content, 'UTF-8')
}
where my strings.xml is -
<string name="app_id">some_app_id</string>
Now, server urls are stored in my Config.java file as normal constant-
public static final String BASE_URL = "http://dev.blahblah.com";
So the question is how to change this line in Config.java from my build.gradle file depending upon different flavor?