Skip to content

Instantly share code, notes, and snippets.

@martinschneider
Created September 28, 2018 08:03
Show Gist options
  • Select an option

  • Save martinschneider/c205cbfb159abfe46d2361b00337bc5d to your computer and use it in GitHub Desktop.

Select an option

Save martinschneider/c205cbfb159abfe46d2361b00337bc5d to your computer and use it in GitHub Desktop.

Revisions

  1. martinschneider created this gist Sep 28, 2018.
    20 changes: 20 additions & 0 deletions getAppVersion.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #/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