Android 是否保留 .apk 文件?如果是这样在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2507960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:07:31  来源:igfitidea点击:

Does Android keep the .apk files? if so where?

androidpackagesapkinstaller

提问by Gubatron

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

android 从 Marketplace 安装应用程序后,它会保留 .apk 文件吗?

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

Android 是否有保存此类文件的标准位置?

采纳答案by Macarse

Preinstalled applications are in /system/appfolder. 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:

预安装的应用程序位于/system/app文件夹中。用户安装的应用程序位于/data/app. 我想除非你有一个root手机,否则你无法访问。我这里没有根电话,但试试这个代码:

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.

它确实列出了我扎根的 htc magic 和 emu 中的 apk。

回答by Mariusz Jamro

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

您可以使用包管理器 ( pm)adb shell来列出包:

adb shell pm list packages | sort

and to display where the .apkfile is:

并显示.apk文件所在的位置:

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

And adb pullto download the apk.

adb pull下载apk。

adb pull data/app/com.king.candycrushsaga-1/base.apk

回答by Jan Przybylo

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

如果您只想获取之前安装的某个 APK 文件,请执行以下操作:

  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
  1. 从 Google Play 获取 AirDroid
  2. 从您的 PC 网络浏览器使用 AirDroid 访问您的手机
  3. 转到应用程序并选择已安装的应用程序
  4. 点击“下载”按钮从您的手机下载此应用程序的APK版本

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

你不需要root你的手机,使用adb,或者写任何东西。

回答by hackbod

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

没有标准位置,但是您可以使用 PackageManager 来查找有关包的信息,您可以从中获取的 ApplicationInfo 类具有有关特定包的各种信息:其 .apk 的路径、其数据目录的路径、路径到仅限资源的 .apk(用于前向锁定应用程序)等。请注意,根据您与其他应用程序的关系,您可能有也可能没有权限读取这些目录;但是,所有应用程序都能够读取资源 .apk(这也是非前向锁定应用程序的真正 .apk)。

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.

如果您只是在 shell 中闲逛,当前非前向锁定的应用程序位于 /data/app/.apk 中。shell 用户可以读取特定的 .apk,但它无法列出目录。在未来的版本中,命名约定会略有变化,所以不要指望它保持不变,但是如果您从包管理器中获得 .apk 的路径,那么您可以在 shell 中使用它。

回答by xmaslatte

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

预安装的应用程序通常位于 /system/app 中,而用户安装的应用程序位于 /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?

可以使用“adb pull”,但需要知道APK文件的完整路径。在模拟器上,您可以使用“adb shell”+“ls”获取目录列表。但是在 Android 设备上,出于安全原因,您将无法在“/data”文件夹中执行此操作。那么如何找出APK文件的完整路径呢?

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

您可以通过编写一个查询 PackageManager 的程序来获取所有已安装应用程序的完整列表。下面的简短代码片段:

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

您还可以找到提供此类信息的应用程序。有很多。 试试这个(AppSender)。

回答by tomwhipple

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

如果您正在寻找特定应用程序的路径,一个快速而肮脏的解决方案是 grep 错误报告:

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

我不知道这会提供一个详尽的列表,因此先运行应用程序可能会有所帮助。

回答by alijandro

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.

安装后是否保留apk是市场的行为。安装后谷歌播放不保留apk。其他第三方市场可能有不同的行为。

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

从开发/调试工具(adb、eclipse、android studio)安装

When we install the apk from debug tool, directly invoke adb installor 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 pmcommand to install, it will delete the temporary apk in /data/local/tmp/after the successful installation.

当我们从调试工具安装apk,直接调用adb install或者从eclipse/android studio 安装apk 时,apk 会被传adb push送到( ) 到一个公共的可读写目录中,通常是/data/local/tmp/. 之后,该工具将使用该pm命令进行安装,/data/local/tmp/安装成功后会删除临时apk 。

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

系统如何保存apk

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

当然,系统必须将所有 apk 存储在某个地方。系统有三个地方可以将 apk 保持在不同类型的 apk 上。

  1. for stock app
  1. 对于股票应用

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

这些通常由制造商在设备中提供,包括用于系统运行和谷歌服务的核心应用程序,您可以在目录/system/app/system/priv-app.

  1. user installed app
  1. 用户安装的应用

Most of the apks fall into this category. These apks are usually installed from marketplace by users or by adb installwithout -soption. You can find them under the directory /data/appfor a rooted device.

大多数 apk 都属于这一类。这些 apk 通常由用户从市场安装或adb install不带-s选项安装。您可以在/data/app有根设备的目录下找到它们。

  1. app on sdcard
  1. SD卡上的应用程序

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.

如果 apkandroid:installLocation="auto"在其清单中启用其在 sdcard 中的安装位置,则可以将应用从系统的应用管理器菜单移动到 sdcard。这些 apk 通常位于 sdcard 的安全文件夹中/mnt/sdcard/asec

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

强制安装位置到 sdcard 的另一种方法是使用命令adb install -s apk-to-install.apk.

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

请注意,预安装应用程序的.apk文件不再位于单个文件中。有一个文件夹包含目录中每个预安装应用程序/system/app/system/priv-app最新 android 版本的文件。

回答by Bryan Denny

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

您可以使用 ADB 拉取应用程序。我相信它们在 /data/App/ 中。

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

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

请注意,您必须根植手机才能拉取受复制保护的应用程序。

回答by Tanzer

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.

如果您已 root,请下载应用程序 Root Explorer。根用户的最佳文件管理器。无论如何,系统/应用程序拥有手机附带的所有默认apk,而数据/应用程序拥有您已安装的应用程序的所有apk。只需长按您想要的 apk(在 Root Explorer 中),进入您的 /sdcard 文件夹并粘贴即可。

回答by Robby Pond

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

在 /data/app 但为了复制保护,我认为您无法访问它。