How do I get an apk file from an Android device?
Steps to Download APK from Device to Desktop
A) Make sure that your running (emulator/real Device). To check use this command
adb devices
B) Select all the available package list installed in your device. You can use grep command to select the specific package you intend to download.
adb shell pm list packages
adb shell pm list packages -f -3
Output (List of available packages )
package:/data/app/com.example.mytestapplication-sOzKi5USzfbYLPNDmaaK6g==/base.apk=com.example.mytestapplication
package:/data/app/com.example.myapplication-nd1I4FGnTZnQ9PyRbPDHhw==/base.apk=com.example.myapplication
C) Copy the package (which you like to download) from the above link. Form our case I choose this (com.example.myapplication) package
Syntax : adb shell pm path [your_package_name]
Command: adb shell pm path com.example.myapplication
Output
package:/data/app/com.example.myapplication-nd1I4FGnTZnQ9PyRbPDHhw==/base.apk
D) Finally, To download APK from your (emulator/real device)
Syntax : adb pull /data/app/[your_package_name]-1/base.apk [your_destination_path]
Command: adb pull /data/app/com.example.myapplication-3j4CVk0Tb2gysElgjz5O6A==/base.apk /Users/$(whoami)/Documents/your_apk.apk
Example: Trying to pull this CertInstaller.apk file in your local machine ( Mac )
adb pull /system/app/CertInstaller/CertInstaller.apk /Users/$(whoami)/Documents/APK/download_apk/
E) Confirm in your local directory
ls -la /Users/$(whoami)/Documents/
Use adb. With adb pull you can copy files from your device to your system, when the device is attached with USB.
Of course you also need the right permissions to access the directory your file is in. If not, you will need to root the device first.
If you find that many of the APKs are named "base.apk" you can also use this one line command to pull all the APKs off a phone you can access while renaming any "base.apk" names to the package name. This also fixes the directory not found issue for APK paths with seemingly random characters after the name:
for i in $(adb shell pm list packages | awk -F':' '{print $2}'); do
adb pull "$(adb shell pm path $i | awk -F':' '{print $2}')"
mv base.apk $i.apk &> /dev/null
done
If you get "adb: error: failed to stat remote object" that indicates you don't have the needed permissions. I ran this on a NON-rooted Moto Z2 and was able to download ALL the APKs I did not uninstall (see below) except youtube.
adb shell pm uninstall --user 0 com.android.cellbroadcastreceiver <--- kills presidential alert app!
(to view users run adb shell pm list users) This is a way to remove/uninstall (not from the phone as it comes back with factory reset) almost ANY app WITHOUT root INCLUDING system apps (hint the annoying update app that updates your phone line it or not can be found by grepping for "ccc")
None of these suggestions worked for me, because Android was appending a sequence number to the package name to produce the final APK file name. On more recent versions of Android (Oreo and Pie), an unpredictable random string is appended. The following sequence of commands is what worked for me on a non-rooted device:
1) Determine the package name of the app, e.g. "com.example.someapp". Skip this step if you already know the package name.
adb shell pm list packages
Look through the list of package names and try to find a match between the app in question and the package name. This is usually easy, but note that the package name can be completely unrelated to the app name. If you can't recognize the app from the list of package names, try finding the app in Google Play using a browser. The URL for an app in Google Play contains the package name.
2) Get the full path name of the APK file for the desired package.
adb shell pm path com.example.someapp
The output will look something like
package:/data/app/com.example.someapp-2.apk
or
package:/data/app/com.example.someapp-nfFSVxn_CTafgra3Fr_rXQ==/base.apk
3) Using the full path name from Step 2, pull the APK file from the Android device to the development box.
adb pull /data/app/com.example.someapp-2.apk path/to/desired/destination
No root is required:
This code will get 3rd party packages path with the name so you can easily identify your APK
adb shell pm list packages -f -3
the output will be
package:/data/app/XX.XX.XX.apk=YY.YY.YY
now pull that package using below code:
adb pull /data/app/XX.XX.XX.apk
if you executed above cmd in C:>\
, then you will find that package there.