Android Kernel Development: An analysis of APK installation process

Source: Internet
Author: User

This article is the tenth article of the Android Core Development series, the previous stage, we focused on learning and analyzing the Android system startup process, then, from this article, we are ready to introduce how to add, modify, delete system-level app from Android source. As a starting point, let's start with a simple theory and introduce what the APK file in the Android system really is. How is it installed into the system?


When we learn and understand a new thing, the quickest way is often to compare it with what we know, so let's start with a brief chat about the installation process for Windows applications.


1. The installation process for a general Windows application is divided into the following steps:


(1) Extract EXE files to the temporary directory of the system


This temporary directory is usually C:\Windows\Temp, and of course, not all programs need to be unpacked to a temporary directory.


(2) Copy the core file to the specified program directory


Typically an application contains many files, such as binaries, icons, static libraries, dynamic libraries, configuration files, other resource files, and so on. This process is to copy the necessary files to the target directory, such as: D:\Software\ software name \, of course, some of the software will also copy some important or common DLL files to the system directory (C:\Windows\), such as some driver files, system-level DLL files, Public shared files, and so on.


(3) Write the registration form


Many operations require writing the system's registry, such as the configuration of the installation properties, registering the service program, setting up file associations, adding the right-click menu, registering DLL files, registering yourself in the Add/Remove Programs in Control Panel, and so on.


(4) Add to Start menu and desktop shortcut


This does not have to explain too much, although we can go to the program installation directory every time you click EXE to start the program, but add programs to the Start menu and desktop shortcuts can be more convenient to provide users with access to the program's entrance.


2. Then, let's look at how the APK is installed on the Android system.


(1) Copy the APK file to the specified directory


On Android, the APK installation file is saved, and by default the user-installed apk is first copied to the/data/app directory.


/data/app directory is the user has access to the directory, when the APK installation will automatically select the directory for the user installed files, and the system factory APK file is placed under the/system partition, including/system/app,/system/vendor/app, and/system/priv-app and so on, the partition can only be accessed by the root user, which is why we cannot delete the System factory app until the root phone is not available.


(2) Unzip the APK, copy the file, create the app's data directory


To speed up the app launch, the APK will first copy the app's executable (DEX) to the/data/dalvik-cache directory and cache it when it's installed.


Then, create the application's data directory under the/data/data/directory (named after the app's package name), and store relevant data for the application, such as databases, XML files, caches, binary so dynamic libraries, and so on.


(3) Parsing apk androidmanifinest.xml file


The Android system also has a registry-like thing that records basic information about all currently installed apps, and updates the file every time the system installs or uninstalls any apk files. This file is located in the following directory:


/data/system/packages.xml


During the installation of the APK, the system will parse the APK's Androidmanifinest.xml file and extract important information from the APK to the Packages.xml file, which includes: permissions, app package name, APK installation location, version, UserID and so on.


As a result, we know why some app marketing and software management apps are well aware of all the apps that are currently installed on your phone and the details of those apps.


(4) Other operations


Similar to the Windows app installation, the installation of some apk will also add the Create shortcut to the Launcher app request.


3. Summary


About the APK installation process is briefly introduced here, have any questions or suggestions welcome message or letter [email protected] exchange, or follow my Sina Weibo @ Lu _ June get the latest articles and information.


This article is from the "Shadow Three People" blog, please be sure to keep this source http://ticktick.blog.51cto.com/823160/1669525

Android Kernel Development: An analysis of APK installation process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.