Gradle: preBuild taks generates git.xml in res - usable with getString(R.string.git_hash)

This commit is contained in:
Peter Siegmund
2015-03-30 15:56:49 +02:00
parent cca4a4259c
commit 147b94ff04
5 changed files with 39 additions and 0 deletions
+1
View File
@@ -31,3 +31,4 @@ gen/
out/
.gradle
local.properties
git.xml
@@ -1,4 +1,5 @@
apply plugin: "com.android.application"
apply from: "../git.gradle"
def packageName = "com.sap.sailing.android.tracking.app"
def verCode = 1
@@ -1,4 +1,5 @@
apply plugin: "com.android.application"
apply from: "../git.gradle"
def packageName = "com.sap.sailing.racecommittee.app"
def verCode = 6
+30
View File
@@ -0,0 +1,30 @@
/**
* returns current git hash
*/
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine "git", "log", "-n", "1", "--format='%h'"
standardOutput = stdout
}
return stdout.toString().trim().replace("'", "")
}
/**
* set git hash into git.xml
*/
preBuild.doLast {
copy {
from ("../git.template.xml")
into ("res/values")
rename {
String fileName -> fileName.replace(".template", "")
}
filter {
String line -> line.replaceAll("#GITHASH#", getGitHash())
}
}
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="git_hash" translatable="false">#GITHASH#</string>
</resources>