Auto increment version code in Android app

后端 未结 15 1044
忘掉有多难
忘掉有多难 2020-12-07 08:22

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

15条回答
  •  天涯浪人
    2020-12-07 08:42

    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:

    #!/usr/bin/python
    import re
    
    f = open('AndroidManifest.xml', 'r+')
    text = f.read()
    
    result = re.search(r'(?Pandroid:versionName=")(?P.*)(?P")',text)
    version = str(float(result.group("version")) + 0.01)
    newVersionString = result.group("groupA") + version + result.group("groupB")
    newText = re.sub(r'android:versionName=".*"', newVersionString, text);
    f.seek(0)
    f.write(newText)
    f.truncate()
    f.close()
    

    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!

提交回复
热议问题