Get the application id or manifest package name from android apk.

Saiful Islam
2 min readApr 25, 2019

--

Every android developer knows what a pain is this. For day to day android app development you have to install, uninstall many many apk on your device.

For testing, for analyzing your competitors you need to download single or multiple apk from playstore or from external app store.

Installing an application from command line is easy. You just do:

adb install /Users/saiful103a/Downloads/app-arm64-v8a-debug.apk

Now, after couple of minutes later you decided to uninstall this application…

You know how to do that as well.

adb uninstall apppackagename

But alas!!!, you don’t know the package name of that apk. You ask yourself, if only there was a way to know the package name of that apk.

No worry, aapt here to rescue you.

aapt dump badging /path/of/the/.apk  | awk '/package/{gsub("name=|'"'"'","");  print $2}'

For example:

aapt dump badging /Users/saiful103a/Downloads/app-arm64-v8a-debug.apk  | awk '/package/{gsub("name=|'"'"'","");  print $2}'

You should get package name of this apk. But wait… do you really want to remember all of this?

Certainly i don’t have enough time to remember all of this. Let’s just make a bash script for this.

Put this bash script in a file named ‘get_package.sh’

#!/bin/sh
package=$(aapt dump badging "$*" | awk '/package/{gsub("name=|'"'"'",""); print $2}')
echo "package : $package"

Make the get_package.sh executable:

chmod +x get_package.sh

Now every-time i need to get the package name of an apk all i have to do is this:

./get_package.sh /Users/saiful103a/Downloads/app-arm64-v8a-debug.apk

Better yet, i don’t even have to remember the path of get_package.sh file since i can do this inside my .bash_profile or .bashrc:

alias getapk_package='/Users/saiful103a/get_package.sh'

Now i can do this from anywhere:

getapk_package /Users/saiful103a/Downloads/app-arm64-v8a-debug.apk

This article assumes you know command line/terminal. And have basic idea about how it works. This is a quick note for me to remind myself how to use this command, less i lost it again. If this becomes useful to you, glad this could be of any help to you.

--

--

Saiful Islam

Senior Engineering Manager @Optimizely | Entrepreneur | Infrequent Blogger | Wannabe TechTuber | Cloud Enthusiast