Earlier today I was looking through some files, trying to find some assets that I used in an Android app a few months ago.
Normally I would just go straight to the source code, in this case Visual Studio Team Services, but for some long winded reasons that I won’t go into here, I didn’t have access so it wasn’t that easy.
I did, however, have the app installed on my phone. In this HowTo, I’ll show you how to get at the installed APKs on your device, get them on to your PC and take them apart.
adb.exe, or the Android Debug Bridge, is a command line tool that lets you communicate with an Android device (emulated or physical).
To use adb with a USB connected device, you will need to enable USB Debugging from your devices Developer Options. Now, plug in your phone and “allow USB Debugging” when prompted.
It’s possible that multiple devices are currently attached, so to keep things simple, close down any emulators that you have running and make sure you only have one device attached.
See what apps are installed
Start by opening a command prompt and navigating to the platform-tools folder in the Android SDK:
I prefer to use Cmdr but any command prompt will do.
Next, let’s use adb to take a look at what apps are installed. I’ll be looking for a game I wrote when I was learning Xamarin Forms, called Checkpoint.
adb shell pm list packages -f
adb will query the device and list the package names of the apps currently installed. Scrolling back up the list I can see the package I’m looking for: com.ferrissey.checkpoint
Transfer the package to your PC
Next, back up the package to your PC using this command:
adb backup -apk com.ferrissey.checkpoint
adb will ask you to unlock your device and tap on Backup my Data on your phone screen.
A second or two later, backup.ab should appear in the current folder.
The backup.ab file is actually a compressed .tar file. So first let’s get the file into a format we can work with:
dd if=backup.ab bs=24 skip=1 | openssl zlib -d > backup.tar
then we can use an app like 7Zip or WinZip to extract the files from the .tar:
Now, drill down into the a folder, and unzip the base.apk that you find there.
A quick look around and you’ll find all the familiar Android folders that you are used to.
The Android Debug Bridge has a host of uses, exploring the device and backing up packages is just the tip of the iceberg.
As you get further into your Android development, you’ll find it an invaluable tool.