Skip to content

Instantly share code, notes, and snippets.

@lurecas
Created December 2, 2014 12:41
Show Gist options
  • Save lurecas/43cee67ce110d7dbc098 to your computer and use it in GitHub Desktop.
Save lurecas/43cee67ce110d7dbc098 to your computer and use it in GitHub Desktop.
Append buildType name to appName if not release
applicationVariants.all { variant ->
variant.mergeResources.doLast {
def buildTypeName = variant.buildType.name
if (!buildTypeName.equals("release")) {
println "Modifying app name"
File valuesFile = file(
"${buildDir}/intermediates/res/${variant.dirName}/values/values.xml")
String content = valuesFile.getText('UTF-8')
def root = new XmlSlurper().parseText(content)
def appNameNode = root.depthFirst().
find { it.name() == 'string' && it.@name == 'app_name' }
if (appNameNode != null) {
def oldName = appNameNode.text()
def newName = oldName + " " + buildTypeName
println "Modifying app name from " + oldName + " to " + newName
appNameNode.replaceBody newName
}
// Write modified node and all the file to disk
valuesFile.write(groovy.xml.XmlUtil.serialize(root), 'UTF-8')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment