ChatGPT解决这个技术问题 Extra ChatGPT

How do I get an apk file from an Android device?

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

Can you change the accepted answer to this one? stackoverflow.com/a/18003462/238753 It has over 10x the number of votes and makes it super easy

Y
Yojimbo

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

This is the best answer , no need to rrot the device !! thanks a lot
This worked on all of my Android devices, and should be the accepted answer.
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.
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.
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.
F
Farid Cheraghi

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")


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.......
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.
@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
For instructions, see answer from Yojimbo.
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.
F
Faris Al-Abed

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.


This is awesome answer! Thank you very much :)
For some reason I cannot find APKs in my /data/app/ directory. There is always a subdirectory there.
for system apps use -f -s instead of -f -3
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>
P
Paulo Miguel Almeida

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


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 -
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.
Here are more information if your openssl lacks zlib support: stackoverflow.com/questions/29830981/…
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.
L
Lone Ronin

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/

The objective is to extract a single apk, yet in step 4 you pull two additional files without explanation or previous reference.
I modified this post by clarifying every step.hope this modification will be helpful and easy to understand.
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).
R
RVR
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)

This is the most straightforward way in my opinion. Thanks!
guys using linux or mac instead of findstr use grep
V
Vitaly Dyatlov

One liner which works for all Android versions:

adb shell 'cat `pm path com.example.name | cut -d':' -f2`' > app.apk

@AlexP. what did you want to tell by the link above?
P
Pedro Rodrigues

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


e
elcuco

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.


R
Rohan 'HEXcube' Villoth

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.


@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.
@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.
Does it work if you just adb install all of the APKs for that app separately to restore it?
According to this stackoverflow.com/questions/55212788/… , you've to use a new command 'adb install-multiple apk1 apk2 ...'
a
aditya.gupta

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


O
Oush

Open the app you wish to extract the apk from on your phone. Get the currently opened app with: adb shell dumpsys activity activities | grep mFocusedActivity Get the path to the package name adb shell pm path

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

m
m01

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.


S
SamG

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.


The accepted answer (including the adb shell commands from @Isa A's comment) worked fine for me on Android 7.1.1, not rooted.
J
Jeff Brateman

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.


P
Pramod Mahato

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/


v
vanduc1102

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)

This helped me on a Android 7.0 Huawei device.
m
moberme

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


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.
G
Gerben Versluis

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;
}

Make sure adb(.exe) is in your path or same directory Connect your phone 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.

s
surhidamatya

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:

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

Hope it helps You.


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).
If you are not rotted then you can try App backup and restore play.google.com/store/apps/details?id=mobi.infolife.appbackup
u
user3350906

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 ;)


M
MarSoft

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:

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. 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. 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\""

S
Sirsendu

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.


S
Saahithyan Vigneswaran

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.


It's not easy to use