Created
August 17, 2014 12:06
-
-
Save beartung/178431207d535faffabc to your computer and use it in GitHub Desktop.
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
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