Skip to content

Instantly share code, notes, and snippets.

@iamchiwon
Last active September 6, 2021 13:31
Show Gist options
  • Select an option

  • Save iamchiwon/a0c390258a5e0463c09c737364a6e239 to your computer and use it in GitHub Desktop.

Select an option

Save iamchiwon/a0c390258a5e0463c09c737364a6e239 to your computer and use it in GitHub Desktop.
[Android] increase versionCode
#
# Origin
# https://gist.github.com/drilonrecica/3ca7ca6cc5c347b1d5dad64755a29f7e
#
#!/bin/bash
set -e
function sedi {
if [ "$(uname)" == "Linux" ]; then
sed -i "$@"
else
sed -i "" "$@"
fi
}
cd "app"
newVersionCode=0
# If versionCode is set with = (ex. versionCode = X) change {print $2} to {print $3}
currentVersionCode=`awk '/versionCode/ {print $2; exit;}' ./build.gradle`
echo "Current versionCode is: $currentVersionCode"
# If versionCode is set with = (ex. versionCode = X) change {print $2} to {print $3}
for entry in `awk '/versionCode/ {print $2; exit;}' ./build.gradle`; do
index=`echo ${entry}`
sedi 's/versionCode [0-9]*$/versionCode '$(($index + 1))'/' ./build.gradle
done
# If versionCode is set with = (ex. versionCode = X) change {print $2} to {print $3}
newVersionCode=`awk '/versionCode/ {print $2; exit;}' ./build.gradle`
echo "New versionCode is: $newVersionCode"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment