I'm trying to set up an Android Continuous Integration environment with Jenkins, and I want my versionCode and versionNumber to be incremented by 1 each time the Jenkins build machine runs. The application is built using Apache Ant and I'm trying to avoid including external libraries. I've been looking for a solution to this problem for weeks now and can't seem to get anything to work.
If possible, I need help with:
Finding a way to keep track of the current versionCode and versionName and incrementing by one. One possible solution I found was to create entries in the build.properties file that keeps track of the build number. Incrementing this is easy with 'operation="+"' in build.xml, but actually getting the value (ex. 154) instead of the address (ex. ${build.number}) into the Manifest is impossible!
Getting the actual integer or string value into versionCode and versionNumber, and not an address to a property value. I can't seem to get an actual value into versionCode and versionName with replaceregexp or any other ant replacement task. For example:
<replaceregexp file="/Users/holt.bowmer/Documents/SVNRepo/mobile-trunk/android/AndroidManifest.xml"
match="versionCode=(.*)"
replace= 'versionCode= "${build.number}"' />
Would change versionCode from versionCode= "154" to versionCode= "${build.number}, which isn't allowed!
All in all, this is very frustrating and I've been driving myself crazy trying to find a solution to this problem. Every other stackoverflow or Google solution hasn't worked, so any help at all would be greatly appreciated. This is my first post to stackoverflow so forgive me if things are misplaced or posted incorrectly.
Thanks!
EDIT
Alright, I figured this out and I am going to update my response for anyone else who has to deal with this horrible problem. Why the Jenkins Android Emulator can't do this I'll never understand, but here is my solution:
Step 1: Download the "Hudson Next Build Number" plugin on Jenkins. The trick is to Jenkins' build number automatically increment itself and then use that by calling ${BUILD_NUMBER}. The Hudson Plugin simply lets you set that build number to whatever you want.
Step 2: Under the Build section of your configuration menu, where you call the Android Emulator plugin and (maybe) invoke ant, you want to add a build step. You want to add "Execute shell" and place it at the top of the Build list, before the Emulator and ant.
Step 3: In this shell file you want to put the following code:
sed -i "" "s/android:versionCode=.*/android:versionCode= \"${BUILD_NUMBER}\"/" Users/your.name/Documents/workspace/android/AndroidManifest.xml
sed -i "" "s/"1.3.*"/1.3.${BUILD_NUMBER}\"/" /Users/your.name/Documents/workspace/android/AndroidManifest.xml
For the second shell script you may want to change the "1.3.*" and "1.3.${BUILD_NUMBER} to match the major and minor version numbers you have in your manifest. Also, the file path after the sed call should point to the AndroidManifest.xml you are trying to alter.
Step 4: Go to the "Set Next Build Number" tab in your options menu, right above your build history, and set the build number to whatever you want it to be.
Step 5: Let the Android Emulator Plugin and your ant release do their thing after the shell script runs.
This solved this problem for me, so hopefully I can help somebody else out who is in a similar predicament.