Created
March 29, 2015 12:45
-
-
Save alexsunday/cdaad11245da51c8b965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CUR_DIR=`pwd` | |
if [ ! -f "AndroidManifest.xml" ]; then | |
echo "AndroidManifest.xml NOT FOUND" >&2 | |
exit 1 | |
fi | |
EXISTS_PYTHON=`which python` | |
if [ ! -x "$EXISTS_PYTHON" ]; then | |
echo "PYTHON NOT FOUND" | |
exit 1 | |
fi | |
python <<EOF | |
import xml.etree.ElementTree as ET | |
import sys | |
code_key = '{http://schemas.android.com/apk/res/android}versionCode' | |
name_key = '{http://schemas.android.com/apk/res/android}versionName' | |
manifestfile = 'AndroidManifest.xml' | |
ET.register_namespace("android", "http://schemas.android.com/apk/res/android") | |
tree = ET.ElementTree() | |
tree.parse(manifestfile) | |
root = tree.getroot() | |
ver_code = root.attrib[code_key] | |
ver_name = root.attrib[name_key] | |
if not ver_code: | |
print 'versionCode NOT FOUND in %s' % manifestfile | |
sys.exit(1) | |
try: | |
ver_code = int(ver_code) | |
except ValueError as _: | |
print 'versionCode MUST INTEGER' | |
sys.exit(1) | |
root.attrib[code_key] = str(int(ver_code) + 1) | |
# root.attrib[name_key] = ver_name | |
out = ET.tostring(tree.getroot(), encoding='utf-8', method='xml') | |
with open(manifestfile, 'wt') as f1: | |
f1.write(out) | |
EOF | |
git add AndroidManifest.xml | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
自动为 Android项目增加版本号。