11

I'm looking for a possibility to retrieve both, the package names and the common names of apps installed on an Android device via ADB – or at least to retrieve the common name if the package name is known. A quick search on our site brought up two related questions, but they don't solve my issue:

I'm looking for a way to retrieve the information directly from the device, if possible – not "any" way (including "web lookups" or "via an app") as those two questions have it.

I know there are multiple tools available to obtain package details:

  • adb dumpsys package: While this lists all packages with a bunch of details, the "common name" is not shown
  • adb shell pm list: only gives the package names
  • aapt would be able to obtain the common name, but would require to first pull the .apk file from the device, which is not really convenient (and obviously will be pretty slow with many and/or large apps installed)

Did I miss something? I know the information must be on the device (how else could it show the app names in the GUI? I doubt Android parses the .apk file each time the GUI need the "common name"). So is there a way to get hold of it, using ADB directly?


TL;DR

Background (if somebody's curious): I want to be able to quickly obtain a list of user-apps from any of my devices, without having to revert to acrobatics. A list of their package names I can retrieve using adb shell pm list -3, but as those are package names only, recognizing apps is a guess-work. So if there were some ADB command to retrieve the common name for a given package name, I could simply use a loop like for pkg in $(adb shell pm list -3); do echo "- $(adb <whatever_the_command_is> $pkg) ($pkg)"; done – and get a listing of all the installed user-apps in a "human readable format" together with their package names.

Use-cases:

  • See what "superflous" apps are installed (which I could remove)
  • Cross-check lists from multiple devices
  • Documentation ;)
  • and probably more (but the above 3 are what I need it for)
  • Just an ideea (I think you tried already?). Why you just don't compile aapt for android and run instead from shell? :D – user3344236 May 13 '15 at 10:15
  • @user3344236 I'm aware of that possibility; but it is not always an option to install something to the device in question, especially not a self-compiled binary (I sometimes get handed-in devices which are not rooted, and have to keep "forensics-like conditions" – i.e. "do not alter the device, just explore it"). – Izzy May 13 '15 at 10:37
  • So the second idea is to write yourself a tool which runs via adb shell... without using modified adbd on device and without pushing some files there. I think it will take you some time to accomplish this (if ever you succeed) :D – user3344236 May 13 '15 at 10:50
  • @user3344236 too worrysome, especially as I'm not an Android dev. I currently use a "web based solution" (similar to that "Google Play lookup"), as there doesn't seem to be a native solution here (yet?). – Izzy May 13 '15 at 12:22
  • Hi Izzy! Considering the comments (above), does it mean that you need a solution considering a non-rooted device in mind? – Firelord Jun 24 '15 at 15:13
6

This is not a final answer, as it is not generic (only works on some devices) – but it's a start at least:

As we've figured out, at least CM based ROMs with Kitkat (Android 4.4) and above ship with the aapt binary available in /system/bin1. If your ROM doesn't have it, and installing the binary on the device is an option, you can find it here.

Using aapt, retrieving the app name is possible with

aapt d badging <path to apk> | grep "application: label" |awk '{print $2}'

The output will be something like label='Funny App', which you then easily can parse for the app name, e.g.

aapt d badging <path to apk> | grep 'application: label' | sed -n \"s/.*label\='\([^']*\)'.*/\1/p\"

(not good if the app name contains single quotes, but that might count as cosmetics – or you figure how to improve the sed part to deal with that).


1: we didn't find this in the Kitkat-and-above stock ROMs we've checked, so it might be CM based ROMs only

  • 1
    Note to readers: You need not to have a rooted device to use that aapt binary. You can very well download and rename the binary to aapt in PC, set Linux compatible executable permission on the binary and push it to /data/local/tmp, then use the absolute path /data/local/tmp/aapt to use the binary in those commands. – Firelord Jan 9 '16 at 18:48
5

Here is my solution for a non-rooted phone which needed some slight changes from above which I ran on a Moto G 2nd gen running android 5.0.2.

I didn't have aapt binary in /system/bin, so I first tried downloading from: https://android.izzysoft.de/downloads

but when I tried to run it I got an error saying:

error: only position independent executables (PIE) are supported.

So then I searched for a PIE version and found: https://github.com/Calsign/APDE/blob/master/APDE/src/main/assets/aapt-binaries/aapt-arm-pie

and this worked by copying binary to /data/local/tmp:

adb push aapt-arm-pie /data/local/tmp
adb shell chmod 0755 /data/local/tmp/aapt-arm-pie

So then:

adb shell pm list packages -3 -f

gets list of 3rd party apps (apps you have installed, not system apps) and then you can use package from command above in aapt to get information on package - example:

adb shell /data/local/tmp/aapt-arm-pie d badging /data/app/com.facebook.katana-3/base.apk

So below is script (for a Linux client) to get just "common" name for 3rd party apps:``

for pkg in `adb shell pm list packages -3 -f | awk -F= '{sub("package:","");print $1}'`
do
  adb shell /data/local/tmp/aapt-arm-pie d badging $pkg | awk -F: '
      $1 == "application-label" {print $2}'
done

If you want package and version too, then change last but one line from:

$1 == "application-label" {print $2}'

to:

$1 == "package" { split($2,space," ")
name=space[1];version=space[3]}
$1 == "application-label" {print name, version, $2 }'

Example output:

name='com.ultimarom.launchnavigation' versionName='1.28' 'Navigation' name='com.enhanced.skineditorstudio' versionName='3.3' 'Custom Skin Creator' name='com.mojang.minecraftpe' versionName='1.2.6.60' 'Minecraft' name='org.videolan.vlc' versionName='2.5.13' 'VLC' name='com.jrustonapps.myauroraforecast' versionName='1.7.2' 'My Aurora Forecast' name='de.j4velin.wifiAutoOff' versionName='1.7.6' 'WiFi Automatic' name='com.facebook.katana' versionName='153.0.0.54.88' 'Facebook' name='com.metago.astro' versionName='6.0.5' 'ASTRO File Manager' name='za.co.hardrive.smartinfo.parkrun' versionName='2.0.2' 'My 5krun' name='com.PYOPYO.StarTrackerVR' versionName='1.0.1' 'StarTracker VR' name='cz.aponia.bor3.offlinemaps' versionName='1.1.19' 'Offline Maps' name='com.groupon' versionName='16.11.63973' 'Groupon' name='com.ebay.mobile' versionName='5.16.1.2' 'eBay' name='com.runtastic.android' versionName='8.1.1' 'Runtastic' name='com.google.android.diskusage' versionName='3.8.3' 'DiskUsage'

Mike

  • Thanks a lot and twice, Mike: once for the shell script, and second for the pointer to the ARM variant of aapt! Will check that out as soon as time permits (am a bit in a hurry currently). Upvoted for now, maybe accepted after having verified :) – Izzy Dec 21 '17 at 18:47
  • PS: My download page now also links to the source you've specified – just "one level up", so folks can chose between ARM and x86 builds. – Izzy Jan 6 '18 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.