From b79c0926e53a90d3f1ac5d065f24bb93f091c7fa Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Sun, 3 May 2015 10:29:18 -0400 Subject: [PATCH] populating the version name and code in about.html at build time --- app/build.gradle | 37 +++++++++++++++++++ app/src/main/AndroidManifest.xml | 2 +- app/src/main/assets/.gitignore | 2 + app/src/main/{assets => templates}/about.html | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app/src/main/assets/.gitignore rename app/src/main/{assets => templates}/about.html (97%) diff --git a/app/build.gradle b/app/build.gradle index d85803538..4561dd930 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,5 @@ +import org.apache.tools.ant.filters.ReplaceTokens + apply plugin: 'com.android.application' repositories { @@ -24,6 +26,20 @@ dependencies { compile project(':library:drag-sort-listview') } +def getMyVersionName() { + def parsedManifestXml = (new XmlSlurper()) + .parse('app/src/main/AndroidManifest.xml') + .declareNamespace(android:"http://schemas.android.com/apk/res/android") + return parsedManifestXml.'@android:versionName' +} + +def getMyVersionCode() { + def parsedManifestXml = (new XmlSlurper()) + .parse('app/src/main/AndroidManifest.xml') + .declareNamespace(android:"http://schemas.android.com/apk/res/android") + return parsedManifestXml.'@android:versionCode'.toInteger() +} + android { compileSdkVersion 21 buildToolsVersion "21.1.2" @@ -31,6 +47,8 @@ android { defaultConfig { minSdkVersion 10 targetSdkVersion 21 + versionCode getMyVersionCode() + versionName "${getMyVersionName()}" testApplicationId "de.test.antennapod" testInstrumentationRunner "de.test.antennapod.AntennaPodTestRunner" } @@ -89,4 +107,23 @@ android { lintOptions { abortOnError false } +} + +// about.html is templatized so that we can automatically insert +// our version string in to it at build time. +task filterAbout { + inputs.files files(['src/main/templates/about.html', + 'src/main/AndroidManifest.xml']) + outputs.file 'src/main/assests/about.html' +} << { + copy { + from 'src/main/templates/about.html' + into 'src/main/assets' + filter(ReplaceTokens, tokens: [versionname: android.defaultConfig.versionName, + versioncode: android.defaultConfig.versionCode.toString()]) + } +} + +gradle.projectsEvaluated { + preBuild.dependsOn filterAbout } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7a4c8366e..97f8bbdad 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="1.2"> diff --git a/app/src/main/assets/.gitignore b/app/src/main/assets/.gitignore new file mode 100644 index 000000000..328840cfc --- /dev/null +++ b/app/src/main/assets/.gitignore @@ -0,0 +1,2 @@ +# this file is generated automatically +about.html diff --git a/app/src/main/assets/about.html b/app/src/main/templates/about.html similarity index 97% rename from app/src/main/assets/about.html rename to app/src/main/templates/about.html index af7297564..df7a05b70 100644 --- a/app/src/main/assets/about.html +++ b/app/src/main/templates/about.html @@ -41,7 +41,7 @@