Does Android keep the .apk files? if so where?
Asked Answered
S

20

214

After android installs an application from the Marketplace, does it keep the .apk file?

Is there a standard location where Android would keep such files?

Sacker answered 24/3, 2010 at 13:26 Comment(0)
S
132

Preinstalled applications are in /system/app folder. User installed applications are in /data/app. I guess you can't access unless you have a rooted phone. I don't have a rooted phone here but try this code out:

public class Testing extends Activity {
    private static final String TAG = "TEST";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        File appsDir = new File("/data/app");

        String[] files = appsDir.list();

        for (int i = 0 ; i < files.length ; i++ ) {
            Log.d(TAG, "File: "+files[i]);

        }
    }

It does lists the apks in my rooted htc magic and in the emu.

Southwards answered 24/3, 2010 at 13:48 Comment(6)
This worked like a Charm on Motorola Droid and also on Nexus One both Non-rooted.Sacker
Ok, you never said what you want them for :)Southwards
I want to be able to read them and do things with them. Luckily they are readable.Sacker
Good thing is that not only the files are "listable", they're also readable, so they'll fit my purpose.Sacker
I've read elsewhere that the APKs in /data/app only correspond to apps downloaded from the Play store. Is that correct or does it include anything the user installed?Littman
@Littman /data/app also contains the apks of apps which are not installed from play store too.Extravasation
M
172

You can use package manager (pm) over adb shell to list packages:

adb shell pm list packages | sort

and to display where the .apk file is:

adb shell pm path com.king.candycrushsaga
package:/data/app/com.king.candycrushsaga-1/base.apk

And adb pull to download the apk.

adb pull data/app/com.king.candycrushsaga-1/base.apk
Micaelamicah answered 15/3, 2015 at 11:53 Comment(2)
every app has a folder with the name same as package name but '-1' or '-2' at the end, Any idea why ?Linesman
To specify target file path or name, adb pull /data/app/com.example.app-filename.apk path/to/desired/destinationIllyricum
S
132

Preinstalled applications are in /system/app folder. User installed applications are in /data/app. I guess you can't access unless you have a rooted phone. I don't have a rooted phone here but try this code out:

public class Testing extends Activity {
    private static final String TAG = "TEST";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        File appsDir = new File("/data/app");

        String[] files = appsDir.list();

        for (int i = 0 ; i < files.length ; i++ ) {
            Log.d(TAG, "File: "+files[i]);

        }
    }

It does lists the apks in my rooted htc magic and in the emu.

Southwards answered 24/3, 2010 at 13:48 Comment(6)
This worked like a Charm on Motorola Droid and also on Nexus One both Non-rooted.Sacker
Ok, you never said what you want them for :)Southwards
I want to be able to read them and do things with them. Luckily they are readable.Sacker
Good thing is that not only the files are "listable", they're also readable, so they'll fit my purpose.Sacker
I've read elsewhere that the APKs in /data/app only correspond to apps downloaded from the Play store. Is that correct or does it include anything the user installed?Littman
@Littman /data/app also contains the apks of apps which are not installed from play store too.Extravasation
O
102

If you just want to get an APK file of something you previously installed, do this:

  1. Get AirDroid from Google Play
  2. Access your phone using AirDroid from your PC web browser
  3. Go to Apps and select the installed app
  4. Click the "download" button to download the APK version of this app from your phone

You don't need to root your phone, use adb, or write anything.

Overreach answered 10/8, 2012 at 19:47 Comment(3)
Downvoted because this doesn't really answer the question. What if the OP wanted to use ADB, so that it can be used on devices where debugging is authorised, but password forgotten or screen broken.Combe
easier way to get apk file for unrooted device.Harmonic
Thanx. Upvoted cause it ansers the question by saying in a way: "It keeps them in /data, but only if you do procedure X"Marcelline
P
26

There is no standard location, however you can use the PackageManager to find out about packages and the ApplicationInfo class you can get from there has various information about a particular package: the path to its .apk, the path to its data directory, the path to a resource-only .apk (for forward locked apps), etc. Note that you may or may not have permission to read these directories depending on your relationship with the other app; however, all apps are able to read the resource .apk (which is also the real .apk for non-forward-locked app).

If you are just poking around in the shell, currently non-forward-locked apps are located in /data/app/.apk. The shell user can read a specific .apk, though it can't list the directory. In a future release the naming convention will be changed slightly, so don't count on it remaining the same, but if you get the path of the .apk from the package manager then you can use it in the shell.

Pertinacious answered 24/3, 2010 at 17:11 Comment(2)
what's a "forward locked app"?Sade
It is an old copy protection mechanism that installed the .apk with permissions that only allowed that application to read it.Pertinacious
A
18

Preinstalled Apps are typically in /system/app and user installed apps are in /data/app.

You can use "adb pull", but you need to know the full path of the APK file. On the emulator, you can get a directory listing using "adb shell" + "ls". But on an android device, you will not be able to do that in "/data" folder due to security reasons. So how do you figure out the full path of the APK file?

You can get a full list of all apps installed by writing a program that queries the PackageManager. Short code snippet below:

PackageManager  pm = getPackageManager();
List<PackageInfo> pkginfo_list = pm.getInstalledPackages(PackageManager.GET_ACTIVITIES);
List<ApplicationInfo> appinfo_list = pm.getInstalledApplications(0);
for (int x=0; x < pkginfo_list.size(); x++){             
  PackageInfo pkginfo = pkginfo_list.get(x);
  pkg_path[x] = appinfo_list.get(x).publicSourceDir;  //store package path in array
}

You can also find apps that will give such info. There are lots of them. Try this one (AppSender).

Avisavitaminosis answered 24/5, 2011 at 14:42 Comment(0)
D
11

Install from marketplace

It's the behavior of marketplace whether to keep the apk after installation. Google play doesn't keep the apk after the installation. Other third-party marketplaces might have the different behaviors.

Install from development/debug tool (adb, eclipse, android studio)

When we install the apk from debug tool, directly invoke adb install or from eclipse/android studio, the apk will be transferred (adb push) to a public read and writable directory, usually /data/local/tmp/. After that, the tool will use the pm command to install, it will delete the temporary apk in /data/local/tmp/ after the successful installation.

We could get these information from debug output like following.

$ adb install bin/TestApplication.apk 
3155 KB/s (843375 bytes in 0.260s)
    pkg: /data/local/tmp/TestApplication.apk
Success

How system keeps the apk

Of course the system have to store all apks somewhere. There are three places for the system to keep the apks based on the different types of apks:

  1. for stock app

    Those are usually shipped in device by manufacture, including core app for system running and google service, you can find them under directory /system/app and /system/priv-app.

  2. user installed app

    Most of the apks fall into this category. These apks are usually installed from marketplace by users or by adb install without -s option. You can find them under the directory /data/app for a rooted device.

  3. app on sdcard

    If the apk enable its install location in sdcard with android:installLocation="auto" in its manifest, the app can be moved to sdcard from system's app manager menu. These apks are usually located in secure folder of sdcard /mnt/sdcard/asec.

    Anther way to force the install location to sdcard is using the command adb install -s apk-to-install.apk.

As a note, the files for pre-installed app are not in a single .apk file anymore. There is a folder containing files for every pre-installed app in the directory /system/app or /system/priv-app for the newest android release.

Decoction answered 8/5, 2015 at 7:18 Comment(0)
S
9

If you're looking for the path of a specific app, a quick and dirty solution is to just grep the bugreport:

$ adb bugreport | grep 'dir=/data/app' 

I don't know that this will provide an exhaustive list, so it may help to run the app first.

Sellingplater answered 15/8, 2012 at 17:44 Comment(0)
P
8

You can pull apps with ADB. They are in /data/App/, I believe.

adb pull (location on device) (where to save)

Note that you have to root your phone to pull copy protected apps.

Pleurodynia answered 24/3, 2010 at 13:34 Comment(0)
L
5

In /data/app but for copy protection I don't think you can access it.

Lassitude answered 24/3, 2010 at 13:32 Comment(1)
So how exactly does an app which allows sharing APK via bluetooth work? How do they do it?Hally
G
5

If you are rooted, download the app Root Explorer. Best File manager for rooted users. Anyways, System/app has all the default apks that came with the phone, and data/apk has all the apks of the apps you have installed. Just long press on the apk you want (while in Root Explorer), get to your /sdcard folder and just paste.

Goalkeeper answered 1/3, 2011 at 1:49 Comment(0)
A
5
  • data/app
  • system/app
  • system/priv-app
  • mnt/asec (when installed in sdcard)

You can pull the .apks from any of them:

adb pull /mnt/asec

Aiello answered 16/7, 2015 at 17:24 Comment(0)
B
4

Use this to list all .apks under /data/app/

adb bugreport | grep 'package name="' | grep 'codePath="/data' | cut -d'"' -f4
Bankable answered 31/1, 2013 at 9:48 Comment(0)
P
3

.apk files can be located under /data/app/ directory. Using ES File Explorer we can access these .APK files.

Patrolman answered 31/8, 2015 at 13:18 Comment(0)
P
2

if you are using eclipse goto DDMS and then file explorer there you will see System/Apps folder and the apks are there

Pechora answered 28/10, 2011 at 12:30 Comment(0)
C
0

When i installed my app on emulator, it showed my the .apk file in

data/app Then I used ls data/app //to see if it exists or not

After you install your app just use ls command vie shell and check desired directory but it depends what kind of application you are trying to install. I used this method to Install Point if any thing is wrong.

Cutcherry answered 10/6, 2010 at 21:11 Comment(1)
I am also trying to locate apks but what I found is that you cannot locate all the apks thus i suggest the rooting method. I wasnt able to get all theinstalled apks. So its better to root your phone and get all the apks using Titanium Backup and gain more control over your phone.Pechora
C
0

Another way to get the apks you can't find, on a rooted device is with rom tool box.

Make a backup using app manager then go to storage/emulated/appmanager and check either system app backup or user app backup.

Cowherb answered 26/4, 2014 at 4:21 Comment(0)
Z
0

To find an apk, download and Install the Bluetooth App Sender from Play store. Once installation completes open the Bluetooth App Sender. It will show all the apps (.apk) installed in your device, then you can easily transfer the app to your PC through Bluetooth.

Zack answered 25/7, 2014 at 12:10 Comment(0)
Z
0

As opposed to what's written on the chosen answer, you don't need root and it is possible to get the APKs of the installed apps, which is how I've done it on my app (here). Example:

List<PackageInfo> packages=getPackageManager().getInstalledPackages(0);

Then, for each of the items of the list, you can access packageInfo.applicationInfo.sourceDir, which is the full path of the APK of the installed app.

Zonda answered 5/5, 2015 at 18:20 Comment(0)
A
0
  1. Install Total Commander.
  2. Open Installed apps on the main page.
Adrianadriana answered 20/3, 2022 at 13:0 Comment(0)
N
-1

Well I came to this post because I wanted to reinstall some app I liked much. If this is your case, just go to Google Play, and look for My Apps, the tab All, and you will find a way to reinstall some app you liked. I faced a problem that I could not find by search one app, but it was there in My apps so I could reinstall in my new mobile ;)

Nkvd answered 26/7, 2016 at 3:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.