is there a way to auto-increment the version code each time you build an Android application in Eclipse?
According to http://developer.android.com/guide/publishing/versioning.html, you have to manually increment your version code in AndroidManifest.xml
.
I understand, you have to run a script before each build which would, e.g. parse AndroidManifest.xml file, find the version number, increment it and save the file before the build itself starts. However, i couldn't find out how and if Eclipse supports runnings scripts before/after builds.
I have found this article about configuring ant builder, but this is not exactly about Android and I fear this will mess up too much the predefined building steps for Android?
Should be a common problem, how did you solve it?
Well, one can do this manually, but as soon as you forget to do this chore, you get different versions with the same number and the whole versioning makes little sense.
Building on Rocky's answer I enhanced that python script a bit to increase also versionCode, works for me on Eclipse (integrated as per ckozl great tutorial) & Mac OSX
also don't forget to
chmod +x autoincrement.py
and make sure you have correct path to python on the first line (depending on your environment) as sulai pointed outFWIW, I was able to update the build version value in six lines of python:
If you're using gradle then you can specific
versionName
andversionCode
very easy inbuild.gradle
. You can use git commit count as an increasing number to identify the build.You can also use this library: https://github.com/rockerhieu/Versionberg.
I've done something similar but written it as a Desktop AIR app instead of some external C# (didn't feel installing another build system). Build this Flex/ActionScript app and change the path to your file, the build it as a standalone desktop app. It rewrites the 1.2.3 part of your file.
Building on Charles' answer, the following increments the existing build version:
For those that are on OSX and want to use Python, but not loose the XML formatting which when parsing is done by the python XML parser happens, here is a python script that will do the incremental based on regular expression, which keeps the formatting:
The code was based on @ckozl answer, just was done in python so you don't need to create an executable for this. Just name the script autoincrement.py, place it in the same folder with the manifest.xml file and then do the steps that ckozl did describe above!