Well, I watched a video on YouTube with Xavier Ducroet in the new Android build system. I even switched to using Android Studio and am happy with it. Now I need to configure the assembly rules to do what I want, and one of them automatically sets codeVersion and codeName in the manifest file.
Xavier shows the beginning of how to do this in one of his slides:
def getVersionCode() { def code = ... return code } android { defaultConfig { versionCode getVersionCode() } }
So can anyone be so kind as to point me to a good resource for filling out the points?
To be more specific, I want to run a script as git describe --dirty | sed -e 's/^v//' git describe --dirty | sed -e 's/^v//' to specify versionName and git tag | grep -c ^v git tag | grep -c ^v to get versionCode .
thanks
Update
I tried the following gradle.build script with no success. It works fine, but the version name on the application details page of my installed applications does not change.
task getVersionName(type:Exec) { commandLine '../scripts/version-name.sh' //store the output instead of printing to the console: standardOutput = new ByteArrayOutputStream() //extension method stopTomcat.output() can be used to obtain the output: 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() } }
If I replaced config versionName getVersionName() with versionName 'Some Text' , then it will work and the assembly name will become Some Text in the Info application. So why is my getVersionName function not working?
Update 2
Still not working - but almost!
Shell script:
#/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}
This works, and the log line confirms that the script is called several times when creating the project. But versionName is still empty. I suspect this is the Gradle side that is still not getting stdout.
task getVersionCode(type: Exec) { exec { commandLine '../scripts/version-code.sh' } //store the output instead of printing to the console: standardOutput = new ByteArrayOutputStream() ext.output = { return standardOutput.toString() } } 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 versionCode getVersionCode() versionName getVersionName.output() } }
android-studio build.gradle gradle
Dobo
source share