Android:了解APK安装过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12442979/
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
Android: Understanding the APK installation process
提问by user1631295
I am trying to understand the process of how an apk is installed on Android, specifically the Android SDK emulator via adb install (where i am testing).
我试图了解如何在 Android 上安装 apk 的过程,特别是通过 adb install (我正在测试的地方)安装 Android SDK 模拟器。
In searching I have found no satisfactory answer outside of "the apk is simply copied to /data/app and is installed when you run it. This is not satisfactory to me as it does not explain how the apk's icon appears on the menu amongst other issues.
在搜索中,除了“apk 被简单地复制到 /data/app 并在您运行它时安装它之外,我没有找到令人满意的答案。这对我来说并不令人满意,因为它没有解释 apk 的图标如何出现在菜单中”问题。
Coming from a Windows background, running an .exe or installer to install a program modifies registries, files, services, etc.... I need to understand if this or something similar occurrs when an apk is installed on Android.
来自 Windows 背景,运行 .exe 或安装程序来安装程序会修改注册表、文件、服务等......我需要了解在 Android 上安装 apk 时是否会发生这种情况或类似的事情。
So if anyone can explain to me what occurrs specifically when an apk is installed on Android I would greatly appreciate it.
因此,如果有人能向我解释在 Android 上安装 apk 时具体发生了什么,我将不胜感激。
On a side note I would also like to know if the Dalvik VM "zygote
" is involved in the installation or does it occur at the lower linux kernel level?
附带说明一下,我还想知道 Dalvik VM " zygote
" 是否参与安装,还是发生在较低的 linux 内核级别?
My ultimate goal here is to use strace to caputer the installation process of an apk to document system modifications, file creations, network activity and other events of interest.
我的最终目标是使用 strace 捕获 apk 的安装过程,以记录系统修改、文件创建、网络活动和其他感兴趣的事件。
回答by sappu
There are mainly two categories of Android applications.
Android 应用程序主要有两类。
- System Apps: installed when system is initialized
- User Apps: installed from Play store, using ADB or copying .apk file in SD card.
- 系统应用:系统初始化时安装
- 用户应用程序:从 Play 商店安装,使用 ADB 或将 .apk 文件复制到 SD 卡中。
Following are the step by step installation process.
以下是分步安装过程。
- AndroidManifest.xml is parsed, information is extracted and stored into /data/system/packages.xml and /data/system/packages.list
- .apk file is copied to a specific directory and a directory for data storage is created for this app
- AndroidManifest.xml 被解析,信息被提取并存储到/data/system/packages.xml 和/data/system/packages.list
- .apk 文件复制到特定目录,并为此应用创建数据存储目录
XML parsing, resource analysis, and .apk file copying are done by
XML 解析、资源分析和 .apk 文件复制由
PackageManageService.java
包管理服务.java
however, directory creation is done by
但是,目录创建是由
installd.c
安装文件
PackageManageService.java communicates with installd.c via a local socket, located at /dev/socket/installed
PackageManageService.java 通过位于 /dev/socket/installed 的本地套接字与 installd.c 通信
Package where .apk file got copied is different for system apps and user apps. for system apps it is
.apk 文件被复制的包对于系统应用程序和用户应用程序是不同的。对于系统应用程序,它是
/system/app/
/系统/应用程序/
Where as for user app .apk file copied in to .apk file is copied to
至于用户应用程序 .apk 文件复制到 .apk 文件的位置被复制到
/data/app
/数据/应用程序
.dex file, which is extracted from the .apk file, is copied to /data/dalvik-cache/.
从 .apk 文件中提取的 .dex 文件被复制到 /data/dalvik-cache/。
Package Manager creates data directory /data/data// to store database, shared preference, native library and cache data
包管理器创建数据目录 /data/data// 来存储数据库、共享首选项、本机库和缓存数据
回答by pandabear
Everything that you want to know, I think, is in the Android develeper website http://developer.android.com/tools/building/index.htmland to understand packaging of the app itself, here is the image better (it's not the APK installation process, but it can help you understand the apk structure and instalation).
You can also google about aapt tool and .dex to understand more because classes.dex is the substruction of your application - contains the java and classes compiled. One dex file contains multiple classes as opposed to java class file which contain only that one class.
dex file is java bytecode converted with DX tool which is integral part of Android SDK. As a result of that, it allows every application to run as its own process with its own instance of the Dalvik virtual machine.
我认为,你想知道的一切都在 Android 开发者网站http://developer.android.com/tools/building/index.html 中,为了了解应用程序本身的包装,这里有更好的图像(它不是APK 安装过程,但它可以帮助您了解 APK 结构和安装)。您还可以通过谷歌搜索 aapt 工具和 .dex 以了解更多信息,因为 classes.dex 是您的应用程序的子结构 - 包含已编译的 java 和类。一个 dex 文件包含多个类,而 java 类文件只包含一个类。dex 文件是用 DX 工具转换的 java 字节码,它是 Android SDK 的组成部分。因此,它允许每个应用程序作为自己的进程运行,并拥有自己的 Dalvik 虚拟机实例。
回答by Yogesh Sharma
This is done at two levels 1.) PackageInstaller(UI) using PackageManagerService(System service) sending command to 2nd part(Installd) 2.) Installd is a daemon which actually install the apk. Installd and PackageManagerService communicate using socket communication . Socket used is installd itself. You can refer to init.rc for the socket creation at init.
这是在两个级别完成的 1.) PackageInstaller(UI) 使用 PackageManagerService(System service) 发送命令到第二部分(Installd) 2.) Installd 是一个实际安装 apk 的守护进程。Installd 和 PackageManagerService 使用套接字通信进行通信。使用的套接字是自己安装的。您可以参考 init.rc 在 init 中创建套接字。