Skip to content

Instantly share code, notes, and snippets.

@beartung
Created August 17, 2014 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beartung/178431207d535faffabc to your computer and use it in GitHub Desktop.
Save beartung/178431207d535faffabc to your computer and use it in GitHub Desktop.
def manifestVersionName() {
def manifestFile = file(project.projectDir.absolutePath + '/AndroidManifest.xml')
def ns = new groovy.xml.Namespace("http://schemas.android.com/apk/res/android", "android")
def xml = new XmlParser().parse(manifestFile)
return xml.attributes()[ns.versionName].toString()
}
def manifestVersionCode() {
def manifestFile = file(project.projectDir.absolutePath + '/AndroidManifest.xml')
def ns = new groovy.xml.Namespace("http://schemas.android.com/apk/res/android", "android")
def xml = new XmlParser().parse(manifestFile)
return xml.attributes()[ns.versionCode].toString()
}
project.ext.versionName = manifestVersionName()
project.ext.versionCode = manifestVersionCode()
def appendVersionNameVersionCode(variant) {
if(variant.zipAlign) {
def file = variant.outputFile
def fileName = file.name.replace(".apk", "-" + project.ext.versionName + "-" + project.ext.versionCode + ".apk")
variant.outputFile = new File(file.parent, fileName)
}
def file = variant.packageApplication.outputFile
def fileName = file.name.replace(".apk", "-" + project.ext.versionName + "-" + project.ext.versionCode + ".apk")
variant.packageApplication.outputFile = new File(file.parent, fileName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment