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
If you're using gradle then you can specific versionName and versionCode very easy in build.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.
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
#!/usr/bin/python
from xml.dom.minidom import parse
dom1 = parse("AndroidManifest.xml")
oldVersion = dom1.documentElement.getAttribute("android:versionName")
oldVersionCode = dom1.documentElement.getAttribute("android:versionCode")
versionNumbers = oldVersion.split('.')
versionNumbers[-1] = unicode(int(versionNumbers[-1]) + 1)
dom1.documentElement.setAttribute("android:versionName", u'.'.join(versionNumbers))
dom1.documentElement.setAttribute("android:versionCode", str(int(oldVersionCode)+1))
with open("AndroidManifest.xml", 'wb') as f:
for line in dom1.toxml("utf-8"):
f.write(line)
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 out
FWIW, I was able to update the build version value in six lines of python:
#!/bin/env python
import os
from xml.dom.minidom import parse
dom1 = parse("AndroidManifest.xml")
dom1.documentElement.setAttribute("android:versionName","%build.number%")
f = os.open("AndroidManifest.xml", os.O_RDWR)
os.write( f, dom1.toxml() )