Skip to content

Instantly share code, notes, and snippets.

@djyugg
Last active Jan 12, 2021
Embed
What would you like to do?
Update Android build.gradle for versionCode and versionName
#!/bin/sh
# versionName
APP_VERSION_NAME=${1}
APP_BUILD_GRADLE=./app/build.gradle
# replace versionCode
CURRENT_VERSION_CODE=`grep versionCode ${APP_BUILD_GRADLE} | sed 's/ *//' | cut -d' ' -f2`
NEXT_VERSION_CODE=`expr ${CURRENT_VERSION_CODE} + 1`
sed -i "" "s/versionCode *[0-9]*/versionCode ${NEXT_VERSION_CODE}/" ${APP_BUILD_GRADLE}
# replace versionName
sed -i "" "s/versionName *'.*'/versionName '${APP_VERSION_NAME}'/" ${APP_BUILD_GRADLE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment