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/v
This shell script, suitable for *nix systems, sets the versionCode and the last component of versionName to the current subversion revision. I'm using Netbeans with NBAndroid and I call this script from the target -pre-compile in custom_rules.xml.
Save this script in a file called incVersion in the same directory as AndroidManifest.xml, make it executable: chmod +x incVersion
manf=AndroidManifest.xml
newverfull=`svnversion`
newvers=`echo $newverfull | sed 's/[^0-9].*$//'`
vers=`sed -n '/versionCode=/s/.*"\([0-9][0-9]*\)".*/\1/p' $manf`
vername=`sed -n '/versionName=/s/.*"\([^"]*\)".*/\1/p' $manf`
verbase=`echo $vername | sed 's/\(.*\.\)\([0-9][0-9]*\).*$/\1/'`
newvername=$verbase$newverfull
sed /versionCode=/s/'"'$vers'"'/'"'$newvers'"'/ $manf | sed /versionName=/s/'"'$vername'"'/'"'$newvername'"'/ >new$manf && cp new$manf $manf && rm -f new$manf
echo versionCode=$newvers versionName=$newvername
Create or edit custom_rules.xml and add this:
So if my current svn revision is 82, I end up with this in AndroidManifest.xml:
android:versionCode="82"
android:versionName="2.1.82">
When I want to release a new version I'll typically update the first parts of versionName, but even if I forget, the last part of versionName (which is exposed in my About activity) will always tell me what svn revision it was built from. Also, if I have not checked in changes, the revision number will be 82M and versionName will be something like 2.1.82M.
The advantage over simply incrementing the version number each time a build is done is that the number stays under control, and can be directly related to a specific svn revision. Very helpful when investigating bugs in other than the latest release.