dacongy dacongy - 1 year ago 61
Android Question

What exactly happens when I install an android application?

My guess is that the contents of .apk package are extracted somewhere, and the application is registered at some directory so that the application launcher or whatever can find it. But is that all? If that is the case, is the original manifest.xml read every time the app is launched or it gets pre-processed into some other form?

Answer Source

Some basics

The .apk-file

An .apk-file is not magical at all. It's just a bundle of files which represent the content of an Android application. If you open it in a archive-tool (like 7Zip), you can browser and extract it's contents.

Android is Linux

The basic Android-System is a Linux system. Android uses a custom Linux kernel with some extra functionality on power-saving and some speed-improvements. The internal storage of an Android device is formatted with the YAFFS2-filesystem, which fully features the Linux-like access-concepts.

The used file-system might differ by manufacture or Android-Version. Newer devices often use ext3, while Samsung uses it's own file-system: RFS

This is one important aspect of the Sandbox-system, which is used by Android.

Compiling applications

What happens to the .java-files?

Well, first they are normally compiled by an installed JDK implementation. After they are compiled (to .class-files), the dx-tool from the Android SDK then cross-compiles those "normal" java-classes into Dalvik-Bytecode.

This "special" java-code is then interpreted by the DVM (Dalvik Virtual Machine), which is based on the opensource JRE-implementation Apache Harmony.

What happens to the resources i put into the /asset-directory?

Android offers the /assets-directory to add some binary raw-files (e.g. a SQLite Database). Files which are put into this directory are not compiled or optimized.

If you put your files into this directory, this is the kind of behavior you would expect from Android.

What happens to the resources i put into the /res/raw-directory?

Like the /assets-directory, you can also put binary (or other) raw-files in here (e.g. HTML-files for the Help-page). These files are compiled/optimized (if possible).

What happens to the Manifest and the other XML-files?

The Android-Manifest and also the other XML-files (Layouts, Strings, etc.) are stored and "compiled" into a binary XML-format. This is a speed-optimization.

The Sandbox

From Android OS point of view, a single Application owns:

  • it's own process,
  • it's own OS-User (like on Linux),
  • it's own DVM,
  • it's own place in the heap and
  • it's own place on the filesystem.

So yes, every Android app has it's own user which has the proper rights to access it's place in the internal storage (which is protected by standard Linux filesystem rights-management) and it's own DVM-process (which can't be accessed from outside of the application).

To give the application the possibility to leave the Sandbox (e.g. to connect to the Internet), the permissions declared in the Android Manifest are used.

Steps during the installation

So from the above explanations, it should be clear what happens when an Android-Application is installed:

  1. The new user for the Application is created.
  2. With this new users rights, the Applications directory in the internal storage is created.
  3. The contents of the .apk-file are being extracted there.
  4. The Android-Manifest is parsed and the declared intent-filters are registered (e.g. the android.intent.category.LAUNCHER-filter for the applications standard entry point).
  5. Now the application is ready for it's first launch.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download