Skip to content

Instantly share code, notes, and snippets.

@ursimon
Created October 9, 2013 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ursimon/6903019 to your computer and use it in GitHub Desktop.
Save ursimon/6903019 to your computer and use it in GitHub Desktop.
python script to auto-increment AndroidManifest.xml versionName + versionCode
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment