Created
December 2, 2014 12:41
-
-
Save lurecas/43cee67ce110d7dbc098 to your computer and use it in GitHub Desktop.
Append buildType name to appName if not release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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