Monday, July 23, 2012

What Happens During Android Application Installation Process?

You can install an app on Android in 4 ways.

1. system apps, installed when system is initialized.
2. Install apps from Google Play Store.
3. Install apps using adb, "adb install xxx.apk".
4. Copy xxxapp.apk to sdcard, browse the .apk file from your phone, double click, the app would be                  installed.

What is inside an app package, i.e. the .apk file?

  • META-INFO/jar, contains signature info
  • res/, necessary resources
  • AndroidManifest.xml, app configuration and permission requirements
  • classes.dex, dalvik byte-code
  • resources.arsc, binary resource file after compiling

Which files are needed for an app to be run?

-- appname.apk, underlying libraries.

What happened during installation?

  • 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

File copy and directory creation

1. For system apps
  • .apk file is copied to /system/app/
  • two directories for this app are created, respectively, /data/data/com.app.appname/ and /data/data/com.app.appname/lib
  • .dex file, which is extracted from the .apk file, is copied to /data/dalvik-cache/, named as, e.g. system@app@appname.apk.dex
2. Apps installed by adb
  • .apk file is copied to /data/app
  • two directories for this app are created, respectively, /data/data/com.app.appname/ and /data/data/com.app.appname/lib
  • .dex file, which is extracted from the .apk file, is copied to /data/dalvik-cache/, named as, e.g. system@app@appname.apk.dex
3. Apps installed from Google Play Store
  • the same as apps installed by adb
4. Apps installed from sdcard

  • the same as apps installed by adb

How is installation implemented?

  • xml parsing, resource analysis and .apk file copy are done by PackageManageService.java
  • directory creation is done by installd.c
  • PackageManageService.java communicates with installd.c via a local socket, located at /dev/socket/installd



2 comments:

  1. Thanks , It's very helpful. Every time i ask it people start telling APK building process.

    ReplyDelete