Skip to content

Instantly share code, notes, and snippets.

@KyleLeneau
Forked from laomo/InspectAPK.sh
Created July 15, 2016 07:20
Show Gist options
  • Save KyleLeneau/7fccbdaeaea332e882382c8b89eaaa00 to your computer and use it in GitHub Desktop.
Save KyleLeneau/7fccbdaeaea332e882382c8b89eaaa00 to your computer and use it in GitHub Desktop.
Inspect APK's info like package name, version code, version name, etcetera
#!/bin/bash
apk_file=$1
if [ -z $apk_file ]; then
apk_file_num=`ls *.apk | wc -l | tr -d ' '`
if [ $apk_file_num -gt 1 ]; then
echo "Ambiguous apk_files. Please enter one APK to inspect."
exit -1
fi
apk_file=`ls *.apk`
fi
if [ -z $ANDROID_HOME ]; then
echo "Error: Please set ANDROID_HOME to environment variable."
exit -1
fi
# Add aapt to path
for aapt_path in ${ANDROID_HOME}/build-tools/*/; do break; done
export PATH="$PATH:${aapt_path}"
package=`aapt dump badging $apk_file | grep package | awk '{print $2}' | sed s/name=//g | sed s/\'//g`
versionCode=`aapt dump badging $apk_file | grep versionCode | awk '{print $3}' | sed s/versionCode=//g | sed s/\'//g`
versionName=`aapt dump badging $apk_file | grep versionName | awk '{print $4}' | sed s/versionName=//g | sed s/\'//g`
sdkVersion=`aapt dump badging $apk_file | grep sdkVersion | sed s/sdkVersion://g | sed s/\'//g`
targetSdkVersion=`aapt dump badging $apk_file | grep targetSdkVersion: | sed s/targetSdkVersion://g | sed s/\'//g`
echo
echo 'Package: '$package
echo 'VersionCode: '$versionCode
echo 'VersionName: '$versionName
echo 'SdkVersion: '$sdkVersion
echo 'TargetSdkVersion: '$targetSdkVersion
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment