Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script for changing version code and version name in an android manifest.
MANIFEST_FILE='AndroidManifest.xml'
VERSIONCODE=`grep versionCode $MANIFEST_FILE | sed 's/.*versionCode="//;s/".*//'`
VERSIONNAME=`grep versionName $MANIFEST_FILE | sed 's/.*versionName="//;s/\.[0-9]*".*//'`
NEWCODE=$BUILD_NUMBER
NEWNAME=$VERSIONNAME.$BUILD_NUMBER
echo "Updating Android build information. New version code: $NEWCODE - New version name: $NEWNAME";
sed -i 's/versionCode *= *"'$VERSIONCODE'"/versionCode="'$NEWCODE'"/; s/versionName *= *"[^"]*"/versionName="'$NEWNAME'"/' $MANIFEST_FILE
@AlanVerbner

This comment has been minimized.

Copy link

@AlanVerbner AlanVerbner commented Oct 9, 2014

thanks

@JackLeo

This comment has been minimized.

Copy link

@JackLeo JackLeo commented Nov 21, 2014

In case of simpler version

sed -i.bak 's/android:versionName="."/android:versionName="${version_name}"/g' AndroidManifest.xml
sed -i.bak 's/android:versionCode=".
"/android:versionCode="${BUILD_NUMBER}"/g' AndroidManifest.xml

@sadiq81

This comment has been minimized.

Copy link

@sadiq81 sadiq81 commented Jun 17, 2015

You need to change the last line to
sed -i '' 's/versionCode = *"'$VERSIONCODE'"/versionCode="'$NEWCODE'"/; s/versionName *= *"[^"]"/versionName="'$NEWNAME'"/' $MANIFEST_FILE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment