I’m new to Gradle, having be introduced to it now I’ve switched to using the new build system for Android.
In converting to this new build I am having a problem getting my version script to work with Gradle.
The script looks like this:
#/bin/bash
NAME=‘git describe --dirty | sed -e ‘s/^v//’’
COMMITS=‘echo ${NAME} | sed -e ‘s/[0-9.]*//’’
if [ “x${COMMITS}x” = “xx” ] ; then
VERSION="${NAME}"
else
BRANCH=" (‘git branch | grep “^*” | sed -e ‘s/^…//’’)"
VERSION="${NAME}${BRANCH}"
fi
logger “Build version: ${VERSION}”
echo ${VERSION}
I know it runs each time Gradle builds because I can see the “logger” out in the syslog.
My problem is trying to get the stdout from the script applied to the versionName in the build.gradle script.
task getVersionName(type: Exec) {
exec { commandLine ‘…/scripts/grMobile/scripts/version-name.sh’ }
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}
buildscript {
repositories {
maven { url ‘http://repo1.maven.org/maven2’ }
}
dependencies {
classpath ‘com.android.tools.build:gradle:0.4’
}
}
apply plugin: ‘android’
dependencies {
compile project(’:Common’)
}
android {
compileSdkVersion 17
buildToolsVersion “17.0.0”
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
versionName getVersionName.output()
}
}
The string that gets report when the application is installed on an Android device is blank. So how do I get the output from my script to be returned by the getVersionName task?