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).
In searching
There are mainly two categories of Android applications.
Following are the step by step installation process.
XML parsing, resource analysis, and .apk file copying are done by
PackageManageService.java
however, directory creation is done by
installd.c
PackageManageService.java communicates with installd.c via a local socket, located at /dev/socket/installed
Package where .apk file got copied is different for system apps and user apps. for system apps it is
/system/app/
Where as for user app .apk file copied in to .apk file is copied to
/data/app
.dex file, which is extracted from the .apk file, is copied to /data/dalvik-cache/.
Package Manager creates data directory /data/data// to store database, shared preference, native library and cache data
Everything that you want to know, I think, is in the Android develeper website http://developer.android.com/tools/building/index.html and 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.
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.