How to extract an Android APK off an old device and install it to a new one with ADB
The old OpenIntents shopping list app I have used on my Android phones since around 2011 is no longer available on either the Google Play Store or the F-Droid FOSS Android Repository. I’ve tried several alternatives since getting a new phone earlier this year but much prefer the old OI app so was quite annoyed that it’s gone.
After a few months of struggling with inferior alternatives, today I realised I could simply pull the app off an old phone with ADB and put it on the new one.
The Android Debug Bridge (ADB) is a commandline tool for debugging Android apps, but can also be used for backups, file transfer from PC to/from phone, a remote shell from PC to phone and other purposes.
Assumptions for this Article
You’re fairly familiar with Unix, but not necessarily an Android developer who already knows ADB.
You have a Unix-ish PC with ADB installed (it’s in the package manager for many distros, you don’t need the full Android SDK).
The ADB “server”
When you first run it, ADB will start a server running in the background on your PC. This does the actual communication with the device (the commandline tool “adb” just sends commands to the server):
adb start-server
This doesn’t need to be done manually, the command will automatically start the server if there isn’t one running.
When you’re done using ADB, you do have to manually tell it to close the server with:
adb kill-server
ADB over USB
While you can connect to a device wirelessly, it involves a little more mucking around. Unless you’re using ADB constantly, it’s easier to just plug it in to a USB port when you need to.
The devices command (with -l for long description) should show what is plugged in:
adb devices -l
If it shows as an “unauthorized” device, you need to allow access on the phone (a popup should appear to prompt you for this).
The -d switch to ADB will tell it to use the only connected USB device, so you don’t have to specify which device you want.
Extracting an APK from a device
You need the full path name of the package, so there are a few steps here.
1: List all apps, and if you don’t see it immediately, use grep (etc) to find the full app name of the one you want:
adb -d shell pm list packages adb -d shell pm list packages | grep open
The second command should produce output like this:
package:org.openintents.convertcsv package:org.openintents.shopping package:com.googlecode.opentyrian
2: Using the full app name (which should look a bit like a domain name in reverse), get the path to the APK on the device:
adb -d shell pm path org.openintents.shopping
Note that you don’t want to include the “package:” prefix. That should produce output like this:
package:/data/app/~~C1nq3QXnTBm0KiwBZSNltQ==/org.openintents.shopping-pLhUH30CtqCvZzlZ_YhfxQ==/base.apk
3: Using the path from Step 2, download the APK to your PC:
adb -d pull /data/app/~~C1nq3QXnTBm0KiwBZSNltQ==/org.openintents.shopping-pLhUH30CtqCvZzlZ_YhfxQ==/base.apk open-intents-shopping.apk
Install an APK from a PC to a device
Unplug the old phone, plug in the new one, and then you just need one command:
adb -d install open-intents-shopping.apk