· 5 years ago · Jun 28, 2020, 04:32 AM
1// Set the API key from the WRLD_API_KEY environment variable, as an alternative to modifying strings.xml
2android.applicationVariants.all{ variant ->
3 variant.mergeResources.doLast{
4 def apiKey = System.getenv("WRLD_API_KEY")
5 print "Reading API key from env, WRLD_API_KEY="
6 println apiKey
7
8 if (apiKey != null) {
9 File valuesFile = file("${buildDir}/intermediates/res/merged/${variant.dirName}/values/values.xml")
10 println("Replacing WRLD API key in: " + valuesFile)
11 String content = valuesFile.getText('UTF-8')
12 content = content.replaceAll(/obtain an api key by signing up at wrld3d.com and insert here/, apiKey)
13 valuesFile.write(content, 'UTF-8')
14 }
15 }