From 75b510fb91e9c8a8d6a74a3dbce220bbdd316424 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Tue, 11 Aug 2015 17:06:17 -0500 Subject: Make sure version code is updated in strings --- app/build.gradle | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/build.gradle') diff --git a/app/build.gradle b/app/build.gradle index 9219eb5..0913b4e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -83,6 +83,33 @@ android { } } +def getGitDescription = { -> + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'describe', '--tags', '--dirty' + standardOutput = stdout + } + return stdout.toString().trim() + } catch (ignored) { + return null; + } +} + +// Insert the build number into strings.xml +android.applicationVariants.all { variant -> + variant.mergeResources.doLast{ + ext.env = System.getenv() + def buildNumber = getGitDescription() + if (buildNumber != null) { + File valuesFile = file("${buildDir}/intermediates/res/${variant.dirName}/values/values.xml") + String content = valuesFile.getText('UTF-8') + content = content.replaceAll(/\(working copy\)/, buildNumber) + valuesFile.write(content, 'UTF-8') + } + } +} + if (project.hasProperty('keystorePassword')) { android.signingConfigs.release.storeFile file(keystoreFile) android.signingConfigs.release.storePassword keystorePassword -- cgit v1.2.3