Skip to content

Instantly share code, notes, and snippets.

@kendellfab
Created July 14, 2012 15:35
Show Gist options
  • Save kendellfab/3111850 to your computer and use it in GitHub Desktop.
Save kendellfab/3111850 to your computer and use it in GitHub Desktop.
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
@ivneetsinghwahi03
Copy link

None of the above sed worked!!

@ivneetsinghwahi03
Copy link

ivneetsinghwahi03 commented Jun 28, 2022

Below is the data/file content

versionName 0.0.3

Expected: versionName 0.0.4

Use command:
sed -ie 's/versionName .*/versionName 0.0.4/' "filename"

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