716

How do I get the apk file from an android device? Or how do I transfer the apk file from device to system?

1

26 Answers 26

2008

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.

  1. 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

  1. 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
    
23
  • 3
    I used the above to create a bash script that makes it a one-liner: gist.github.com/anonymous/9109984 Commented Feb 20, 2014 at 9:32
  • 30
    pm list packages supports the -f flag, which lists the location of the .apk for you, like package:/data/app/com.google.android.apps.maps-1.apk=com.google.android.apps.maps. The built-in pm help is useless, but pm can also filter types of packages too, see developer.android.com/studio/command-line/adb.html#pm for more info. EDIT: just noticed that the answer below says this, but that answer isn't nearly as upvoted as this one. Commented Jan 3, 2017 at 14:57
  • 18
    Doesn't work for me. I get the following error: adb: error: remote object '/data/app/path.of.the.app-2/base.apk' does not exist. If I browse these folders with a file browser, the folders are empty.
    – Bevor
    Commented Feb 9, 2018 at 13:56
  • 17
    I had a similar problem as @Bevor, when pulling I got the error that the apk "does not exist". I fixed it by using adb shell and then cp PathToApk /sdcard/ and then copying from the sdcard.
    – colin
    Commented Oct 4, 2018 at 23:34
  • 4
    I had a similar problem as @Bevor, this solves it by using the downloads folder as an intermediate: stackoverflow.com/a/43157127/6067948
    – Watson
    Commented Mar 18, 2020 at 10:45
190

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.

13
  • 1
    THanks Maurits Rijk. Please assist me. I want to copy the iTwips.apk file from the device to system. I am using the following command. is it correct ? I got error "Android2.2Froyo/sdcard/iTwips.apk" does not exits... /Users/bbb/Android/android-sdk-mac_86/tools/adb pull Android2.2Froyo/sdcard/iTwips.apk /Users/bbb Thanks is advance.......
    – Finder
    Commented Oct 27, 2010 at 13:17
  • On my device (Android 2.1) the command would be "adb pull /sdcard/test.jpg" to copy test.jpg from my sd card to the current dir. Please locate your iTwips.apk file first using "adb shell". This start a shell on your device and you can use the standard Unix commands like ls and cd to browse your directories. Commented Oct 27, 2010 at 13:56
  • 30
    @Finder @Maurits Rijk Actually, you don't have to root the device just to pull the apk. As long as you know the full path of that apk. If the apk is installed, find the full path by first looking at the package name with adb shell pm list packages, and its full path adb shell pm path your.package.name then from your pc, you can simply adb pull /full/path/to/your.apk
    – Isa A
    Commented Jun 9, 2016 at 5:10
  • 2
    For instructions, see answer from Yojimbo. Commented Jun 5, 2018 at 18:59
  • 1
    Worth noting that if some APKs have the same name, this will overwrite them, so you really need to do the commands specified by yojimbo instead.
    – Mama Foo
    Commented Feb 20, 2020 at 2:25
152

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.

3
  • 1
    For some reason I cannot find APKs in my /data/app/ directory. There is always a subdirectory there. Commented Apr 25, 2016 at 16:36
  • for system apps use -f -s instead of -f -3
    – palindrom
    Commented Apr 2, 2017 at 9:53
  • If you have a lot of apks, grep can help narrow down the output from the first command, if you know any word in the package name: adb shell pm list packages -f | grep <word from package name>
    – hBrent
    Commented Oct 14, 2020 at 14:20
69

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/
3
  • The objective is to extract a single apk, yet in step 4 you pull two additional files without explanation or previous reference. Commented Feb 25, 2019 at 14:05
  • 1
    I modified this post by clarifying every step.hope this modification will be helpful and easy to understand.
    – Farid Haq
    Commented Feb 26, 2019 at 0:35
  • Also, what's step C for? You already get the package path from pm list packages... You only need that if you only know the apk identifier (but not the package path).
    – msanford
    Commented Sep 7, 2021 at 13:10
61

I've seen that many solutions to this problem either you have to root your phone or you have to install an app. Then after much googling I got this solution for non rooted/rooted phones.

To list which apps you got so far.

adb shell pm list packages

Then you may select an app, for instance twitter

adb backup -apk com.twitter.android

An important thing here is to not set up a password for encrypt your backup

This is going to create a file named as backup.ap, but you still can't open it. For this you got to extract it again but using the dd command.

dd if=backup.ab bs=24 skip=1 | openssl zlib -d > backup.tar

After this all you have to do is to extract the tar content and it's done.

Hope it works for you guys

5
  • 8
    From blog.shvetsov.com/2013/02/…, if your openssl doesn't have zlib, this might work: dd if=backup.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -
    – kodi
    Commented Sep 3, 2013 at 21:55
  • 1
    This is what worked for me, not the procedure in the accepted answer. And it really helped me today when I needed APK of one of my old apps but it was not available to me other than from my phone.
    – zeeshan
    Commented Jul 15, 2014 at 17:53
  • 1
    Here are more information if your openssl lacks zlib support: stackoverflow.com/questions/29830981/… Commented Sep 26, 2017 at 8:41
  • 1
    If, with @kodi 's comment you get UnicodeDecodeError: 'utf-8' codec can't decode byte 0xda in position 1: invalid continuation byte, then replace python by python2 in the command. Commented Mar 7, 2022 at 22:54
  • On some vendors, it is impossible to backup the APK without setting a password. Didn't work for me on the Samsung phone.
    – Veniamin
    Commented Jul 29, 2022 at 11:06
24
C:\Users\xyz>adb shell pm list packages -f | findstr whatsapp
package:/data/app/com.whatsapp-1/base.apk=com.whatsapp

C:\Users\xyz>adb pull /data/app/com.whatsapp-1/base.apk Desktop
/data/app/com.whatsapp-1/base.apk: 1 f.... 13.8 MB/s (32803925 bytes in 
2.269s)
2
  • This is the most straightforward way in my opinion. Thanks! Commented Feb 28, 2018 at 18:23
  • 4
    guys using linux or mac instead of findstr use grep
    – Jeeva
    Commented Feb 21, 2019 at 11:42
14

One liner which works for all Android versions:

adb shell 'cat `pm path com.example.name | cut -d':' -f2`' > app.apk
2
  • 1
    @AlexP. what did you want to tell by the link above? Commented Jun 10, 2018 at 15:05
  • In some cases pm path com.example.name returns multiple apk files, so this command will not work. For me the useful one was the first (named base.apk)
    – xonya
    Commented Dec 31, 2023 at 13:29
12

In June of 2023, use:

adb shell pm list packages --user 0

to list the package names, then:

adb shell pm path your.package.name
adb pull /data/app/your/path/to/package/foo.apk

to get the package(s).

2
  • got base.apk + arm64_v8a.apk + xhdpi.apk instead of single one Commented Aug 25, 2023 at 9:06
  • If there are multiple APKs, it's an Android app bundle (AAB). You get only the APKs specific to your device. Commented Aug 26, 2023 at 10:42
8

On unix systems, you can try this function:

function android_pull_apk() {
    if [ -z "$1" ]; then
        echo "You must pass a package to this function!"
        echo "Ex.: android_pull_apk \"com.android.contacts\""
        return 1
    fi

    if [ -z "$(adb shell pm list packages | grep $1)" ]; then
        echo "You are typed a invalid package!"
        return 1
    fi

    apk_path="`adb shell pm path $1 | sed -e 's/package://g' | tr '\n' ' ' | tr -d '[:space:]'`"
    apk_name="`adb shell basename ${apk_path} | tr '\n' ' ' | tr -d '[:space:]'`"

    destination="$HOME/Documents/Android/APKs"
    mkdir -p "$destination"

    adb pull ${apk_path} ${destination}
    echo -e "\nAPK saved in \"$destination/$apk_name\""
}
  • Example: android_pull_apk com.android.contacts
  • Note: To identify the package: adb shell pm list packages
7

Try this one liner bash command to backup all your apps:

for package in $(adb shell pm list packages -3 | tr -d '\r' | sed 's/package://g'); do apk=$(adb shell pm path $package | tr -d '\r' | sed 's/package://g'); echo "Pulling $apk"; adb pull -p $apk "$package".apk; done

This command is derived from Firelord's script. I just renamed all apks to their package names for solving the issue with elcuco's script, i.e the same base.apk file getting overwritten on Android 6.0 "Marshmallow" and above.

Note that this command backs up only 3rd party apps, coz I don't see the point of backing up built-in apps. But if you wanna backup system apps too, just omit the -3 option.

4
  • 1
    @Pieter Not likely. This was tested before split APKs were common. What this script does is pull the base.apk and rename it to package name of the app. Commented Jun 17, 2020 at 12:21
  • @Pieter You'll need a modification of the script that pulls all apks from that directory and rename them in a sequence or maybe copy them to a directory. Commented Jun 17, 2020 at 12:23
  • Does it work if you just adb install all of the APKs for that app separately to restore it?
    – Pieter
    Commented Jun 17, 2020 at 17:52
  • According to this stackoverflow.com/questions/55212788/… , you've to use a new command 'adb install-multiple apk1 apk2 ...' Commented Jul 13, 2020 at 18:32
7

Completing @Yojimbo 's answer, this is what I did (Linux/Mac only, will not work out of the box on Windows... maybe in git's bash shell):

for i in $(adb shell pm list packages -f -3 | cut -d= -f 1 | cut -d ":" -f 2); do adb pull $i; done

This is ugly bash, but works :)

EDIT: It no longer works on AndroidM: all files are named "base.apk" under another dir. Should be "trivial" to fix.

7
  1. Open the app you wish to extract the apk from on your phone.

  2. Get the currently opened app with:

    adb shell dumpsys activity activities | grep mFocusedActivity
    
  3. Get the path to the package name

    adb shell pm path <packagename.apk>
    

4.Copy the path you got to the sdcard directory

adb shell cp /data/app/<packagename.apk> /sdcard

5.Pull the apk

adb pull /sdcard/base.apk

Edit

If step no 2 doesn't work use this:

adb shell dumpsys window windows | grep mCurrentFocus
6

As said above, you can get the apk by using the pull command in adb.

Since, you are talking about your installed applications, go ahead and look in the /data/app directory of your Android filesystem. You will find the APK's there.

Then use the adb command - adb pull /data/data/appname.apk

5

If you know (or if you can "guess") the path to the .apk (it seems to be of the format /data/app/com.example.someapp-{1,2,..}.apk to , then you can just copy it from /data/app as well. This worked even on my non-rooted, stock Android phone.

Just use a Terminal Emulator app (such as this one) and run:

# step 1: confirm path
ls /data/app/com.example.someapp-1.apk
# if it doesn't show up, try -2, -3. Note that globbing (using *) doesn't work here.
# step 2: copy (make sure you adapt the path to match what you discovered above)
cp /data/app/com.example.someapp-1.apk /mnt/sdcard/

Then you can move it from the SD-card to wherever you want (or attach it to an email etc). The last bit might be technically optional, but it makes your life a lot easier when trying to do something with the .apk file.

5

The procedures outlined here do not work for Android 7 (Nougat) [and possibly Android 6, but I'm unable to verify]. You can't pull the .apk files directly under Nougat (unless in root mode, but that requires a rooted phone). But, you can copy the .apk to an alternate path (say /sdcard/Download) on the phone using adb shell, then you can do an adb pull from the alternate path.

1
  • 3
    The accepted answer (including the adb shell commands from @Isa A's comment) worked fine for me on Android 7.1.1, not rooted. Commented Dec 22, 2016 at 14:54
4

All these answers require multiple steps for each apk file retrieved from the device. 1. determine package name, 2. find the file, and 3. download it. I built a simple apk_grabber python script to do this for any app that matches a given regex, and then decompiles those apks into jar files.

3

Here's how you do it:

Download and install APK Extractor in your device. It is free, and is compatible in almost all of the Android devices. Another plus point is it does not even require root or anything to work. After you have it installed, launch it. There you will see a list of apps which are in your device, which include the apps you’ve installed later, along with the system apps. Long press any app you want to extract (you can select multiple or all apps at once), and click on the extract option you see in the top. You will also have the option to share via Bluetooth or messaging. You’re done, you will see the extracted apps as AppName_AppPackage_AppVersionName_AppVersionCode.apk, which will be saved in the path /sdcard/ExtractedApks/ by default.

For detailed description for how to extract apk files in android, visit: http://appslova.com/how-to-extract-apk-files-in-android/

3

I got a does not exist error

Here is how I make it works

adb shell pm list packages -f | findstr zalo
package:/data/app/com.zing.zalo-1/base.apk=com.zing.zalo

adb shell
mido:/ $ cp /data/app/com.zing.zalo-1/base.apk /sdcard/zalo.apk
mido:/ $ exit


adb pull /sdcard/zalo.apk Desktop

/sdcard/zalo.apk: 1 file pulled. 7.7 MB/s (41895394 bytes in 5.200s)
1
  • This helped me on a Android 7.0 Huawei device. Commented Jul 5, 2020 at 11:11
2

I haven't used code to pull .apk file from mobile but i have been using software to extract .apk file from mobile and software i have used are below with google play link:

  1. ES File Explorer File Manager
  2. ASTRO Cloud & File Manager 3.Software Data Cable

Hope it helps You.

3
  • 2
    I used ES File Explorer. I'm not rooted. I just went to Tools -> App Manager and long-pressed the app I wanted the APK for. This selected the app (and allowed me to select others). I think pressed the Share button and was able to send the APK to myself (using Push Bullet, but what ever works for you).
    – schultzter
    Commented May 23, 2014 at 21:10
  • If you are not rotted then you can try App backup and restore play.google.com/store/apps/details?id=mobi.infolife.appbackup Commented May 27, 2014 at 6:36
  • 1
    Using ES File Explorer File Manager worked on my Nexus 6p - Thank-you! Commented Jun 11, 2023 at 22:18
2

No Root and no ADB tools required method. Install MyAppSharer app from the play store.

1
  • This App by "Jones Chi" has (as of December 2020) 10M+ downloads, 147K reviews with an average rating of 4.6, and it was last updated on November 13th, 2017, just in case anybody was wondering.
    – B--rian
    Commented Dec 19, 2020 at 20:50
2

I really liked all these answers. Most scripts to export and rename all of them were written in Bash. I made a small Perl script which does the same (which should work both in Perl for windows and linux, only tested on Ubuntu).

This uses ADB: https://developer.android.com/studio/command-line/adb

download-apk.pl

#!/usr/bin/perl -w
# Automatically export all available installed APK's using adb
use strict;
print "Connect your device...\n";
system("adb", "wait-for-device");
open(my $OUT, '-|', 'adb', 'shell', 'pm', 'list', 'package', '-f');
my $count = 0;
while(my $line = <$OUT>) {
        $line =~ s/^\s*|\s*$//g;
        my ($type, $path, $package) = $line =~ /^(.*?):(.*)=(.*)$/ ? ($1,$2,$3) : die('invalid line: '.$line);
        my $category = $path =~ /^\/(.*?)\// ? $1 : 'unknown';
        my $baseFile = $path =~ /\/([^\/]*)$/ ? $1 : die('Unknown basefile in path: '.$path);
        my $targetFile = "$category-$package.apk";
        print "$type $category $path $package $baseFile >> $targetFile\n";
        system("adb", "pull", $path);
        rename $baseFile, $targetFile;
}
  1. Make sure adb(.exe) is in your path or same directory
  2. Connect your phone
  3. Run download-apk.pl

The output is something similar to:

# ./download-apk.pl
Connect your device...
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
package system /system/app/YouTube/YouTube.apk com.google.android.youtube YouTube.apk >> system-com.google.android.youtube.apk
5054 KB/s (11149871 bytes in 2.154s)
package data /data/app/com.ghostsq.commander-1/base.apk com.ghostsq.commander base.apk >> data-com.ghostsq.commander.apk
3834 KB/s (1091570 bytes in 0.278s)
package data /data/app/de.blinkt.openvpn-2/base.apk de.blinkt.openvpn base.apk >> data-de.blinkt.openvpn.apk
5608 KB/s (16739178 bytes in 2.914s)
etc.
1

wanna very, very comfortable 1 minute solution?

just you this app https://play.google.com/store/apps/details?id=com.cvinfo.filemanager (smart file manager from google play).

tap "apps", choose one and tap "backup". it will end up on your file system in app_backup folder ;)

0

Yet another bash script (i.e. will work for most unix-based systems). Based on the answer by Pedro Rodrigues, but is slightly easier to use.

Improvements over Pedro's version:

  1. Original approach did not work for me on Android 7: adb pull kept complaining about no such file or directory while adb shell could access the file. Hence I used different approach, with temporary file.
  2. When launched with no arguments, my script will just list all available packages. When partial package name is provided, it will try to guess the full package name. It will complain if there are several possible expansions.
  3. I don't hardcode destination path; instead APKs are saved to current working directory.

Save this to an executable file:

#!/bin/bash
# Obtain APK file for given package from the device connected over ADB

if [ -z "$1" ]; then
    echo "Available packages: "
    adb shell pm list packages | sed 's/^package://'
    echo "You must pass a package to this function!"
    echo "Ex.: android_pull_apk \"com.android.contacts\""
    exit 1
fi

fullname=$(adb shell pm list packages | sed 's/^package://' | grep $1)
if [ -z "$fullname" ]; then
    echo "Could not find package matching $1"
    exit 1
fi
if [ $(echo "$fullname" | wc -l) -ne 1 ]; then
    echo "Too many packages matched:"
    echo "$fullname"
    exit 1
fi
echo "Will fetch APK for package $fullname"

apk_path="`adb shell pm path $fullname | sed -e 's/package://g' | tr '\n' ' ' | tr -d '[:space:]'`"
apk_name="`basename ${apk_path} | tr '\n' ' ' | tr -d '[:space:]'`"

destination="${fullname}.apk"

tmp=$(mktemp --dry-run --tmpdir=/sdcard --suffix=.apk)
adb shell cp "${apk_path}" "$tmp"
adb pull "$tmp" "$destination"
adb shell rm "$tmp"

[ $? -eq 0 ] && echo -e "\nAPK saved in \"$destination\""
0

Personally, using the non-rooted device Samsung Android 13 I prefer the open-source 3rd party application named "Apk Extractor" from F-Droid as the application's usage is a one-click action and you would have extracted the APK file in the Internal storage -> Downloads -> apk -> your_apk.apk

-1

This will help for someone who is looking for a non technical answer

This is simple hack

Download the application App Share/Send Pro from google play store. Select the app you want to send and method send application.

I usually use Bluetooth to send applications to my pc or another phone.

1
  • 1
    It's not easy to use
    – exploitr
    Commented Jun 6, 2018 at 5:35
-2

Simplest one is: Install "ShareIt" app on phone. Now install shareIt app in PC or other phone. Now from the phone, where the app is installed, open ShareIt and send. On other phone or PC, open ShareIt and receive.

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