Skip to content

Instantly share code, notes, and snippets.

@martinschneider
Created September 28, 2018 08:03
Show Gist options
  • Save martinschneider/c205cbfb159abfe46d2361b00337bc5d to your computer and use it in GitHub Desktop.
Save martinschneider/c205cbfb159abfe46d2361b00337bc5d to your computer and use it in GitHub Desktop.
Bash script to extract version information from APK and IPA files
#/bin/bash
#
# Extract the app version number from an APK/IPA file (on Linux)
#
# Required tools: aapt, plistutil, xmllint
#
# Usage:
# ------
# getAppVersion.sh android pathToApk
# getAppVersion.sh ios pathToIpa AppName.app
if [ ${1} = 'android' ]; then
versionName=$(aapt dump badging ${2} | grep -o 'versionName=[^,]*'| cut -d'=' -f 2 | cut -d ' ' -f 1 | tr -d \')
versionCode=$(aapt dump badging ${2} | grep -o 'versionCode=[^,]*'| cut -d'=' -f 2 | cut -d ' ' -f 1 | tr -d \')
elif [ ${1} = 'ios' ]; then
yes | unzip ${2}
versionName=$(plistutil -i Payload/${3}/Info.plist | xmllint --xpath "//key[text()='CFBundleShortVersionString']/following-sibling::string[1]/text()" -)
versionCode=$(plistutil -i Payload/${3}/Info.plist | xmllint --xpath "//key[text()='CFBundleVersion']/following-sibling::string[1]/text()" -)
fi
echo $versionName $versionCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment