Skip to content

Instantly share code, notes, and snippets.

@j796160836
Last active February 22, 2022 16:46
Show Gist options
  • Save j796160836/6ad39ba143bf038bfde8 to your computer and use it in GitHub Desktop.
Save j796160836/6ad39ba143bf038bfde8 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