Skip to content

Instantly share code, notes, and snippets.

@Voronenko
Forked from martinschneider/getAppVersion.sh
Created November 21, 2021 21:08
Show Gist options
  • Save Voronenko/232ac2343ef6ab75b9da2483880bc7ff to your computer and use it in GitHub Desktop.
Save Voronenko/232ac2343ef6ab75b9da2483880bc7ff 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