-
-
Save Morphin3/001b8c744a5c825d4bd0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:0.5.6' | |
} | |
} | |
task wrapper(type: Wrapper) { | |
gradleVersion = '1.7' | |
} | |
apply plugin: 'android' | |
android { | |
compileSdkVersion 17 | |
buildToolsVersion "17.0.0" | |
buildTypes { | |
debug { | |
packageNameSuffix ".debug" | |
versionNameSuffix "-SNAPSHOT" | |
} | |
} | |
} | |
android.applicationVariants.all { variant -> | |
variant.assemble.doLast { | |
rename_and_moveout_apk(variant) | |
} | |
} | |
def rename_and_moveout_apk(targetVariant) { | |
// get hash of current commit | |
new ByteArrayOutputStream().withStream { os -> | |
def result = exec { | |
executable = 'git' | |
args = ['rev-parse', '--short', 'HEAD'] | |
standardOutput = os | |
} | |
project.ext.gitHash = os.toString().trim(); | |
} | |
// replace output apk name to <product>-<version>-<buildtype>-<githash>.apk | |
def versionSuffix = targetVariant.buildType.versionNameSuffix ? targetVariant.buildType.versionNameSuffix : "" | |
def versionName = targetVariant.mergedFlavor.versionName + versionSuffix + "-${gitHash}"; | |
if (targetVariant.zipAlign) { | |
def originZipAlignedApkFile = targetVariant.outputFile; | |
def renameZipAlignedApkFile = originZipAlignedApkFile.name.replace(targetVariant.buildType.name, versionName); | |
copy { | |
from "$originZipAlignedApkFile" | |
into "$rootProject.projectDir/out" | |
rename ("$originZipAlignedApkFile.name", "$renameZipAlignedApkFile") | |
} | |
} | |
def originApkFile = targetVariant.packageApplication.outputFile; | |
def renameApkFile = originApkFile.name.replace(targetVariant.buildType.name, versionName); | |
copy { | |
from "$originApkFile" | |
into "$rootProject.projectDir/out" | |
rename ("$originApkFile.name", "$renameApkFile") | |
} | |
} | |
clean.doLast { | |
project.delete "$rootProject.projectDir/out" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment