populating the version name and code in about.html at build time

This commit is contained in:
Tom Hennen 2015-05-03 10:29:18 -04:00
parent 4e78205e62
commit b79c0926e5
4 changed files with 41 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
repositories { repositories {
@ -24,6 +26,20 @@ dependencies {
compile project(':library:drag-sort-listview') 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 { android {
compileSdkVersion 21 compileSdkVersion 21
buildToolsVersion "21.1.2" buildToolsVersion "21.1.2"
@ -31,6 +47,8 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 10 minSdkVersion 10
targetSdkVersion 21 targetSdkVersion 21
versionCode getMyVersionCode()
versionName "${getMyVersionName()}"
testApplicationId "de.test.antennapod" testApplicationId "de.test.antennapod"
testInstrumentationRunner "de.test.antennapod.AntennaPodTestRunner" testInstrumentationRunner "de.test.antennapod.AntennaPodTestRunner"
} }
@ -90,3 +108,22 @@ android {
abortOnError false 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
}

View File

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.danoeh.antennapod" package="de.danoeh.antennapod"
android:versionCode="51" android:versionCode="51"
android:versionName="1.1.1"> android:versionName="1.2">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

2
app/src/main/assets/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# this file is generated automatically
about.html

View File

@ -41,7 +41,7 @@
<div id="header" align="center"> <div id="header" align="center">
<img src="logo.png" alt="Logo" width="100px" height="100px"/> <img src="logo.png" alt="Logo" width="100px" height="100px"/>
<p>AntennaPod, Version 1.1</p> <p>AntennaPod, Version @versionname@, Build @versioncode@</p>
<p>Copyright © 2014 Daniel Oeh</p> <p>Copyright © 2014 Daniel Oeh</p>