0

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.

Holt B.
  • 3
  • 3
  • That seems like a lot of work to do when all you have to do is type two numbers on two different fields. – yams Jul 01 '13 at 22:29
  • Agreed, but the goal is to make Jenkins build and update the project every time code is checked into the SVN repository. So changing those numbers manually isn't really an option – Holt B. Jul 01 '13 at 22:38
  • Why don't you get the value from the manifest through java. – yams Jul 01 '13 at 22:44

2 Answers2

0

If you're willing to reconsider using an external library, my own library of ant tasks for Android has custom tasks that do exactly what you want:

http://zutubi.com/source/projects/zutubi-android-ant/

In particular, there is a bumpversion task that will increment the versionCode (and optionally versionName) for you.

Jason Sankey
  • 2,328
  • 1
  • 15
  • 12
0

My own Java simple tool to do that is availalbe here: android manifest build number

Features:

  • versionName is supposed to be major.minor.point (as advised by Android doc)
  • versionName can be preserved, reset to 1.0.0, or incremented (one single part of it and trailing part(s) is/are set to 0)
  • versionCode will be replaced by Unix Time
Community
  • 1
  • 1
Pascal
  • 15,257
  • 2
  • 52
  • 65