How APK is Installed

Source: Internet
Author: User

An APK package typically contains the following files

1,assets directory: keep the asset directory in the project, other projects, the asset in the jar package will also be merged into the assets directory

Assets catalog is mainly used for storing some large resource files in the project, for example: Pictures, music, fonts and so on.

2.lib directory: because the jar file is merged into the main project when compiling, Lib contains all so files, the path of so directory retains the original path (CPU type)

3 ,meta-inf directory: information description, signature and other uses

4,res directory: project resource files, mainly in the main project, other files merged, the values file will not appear in this directory, because it has been compiled into the RESOUCES.ARSC file, the raw file will keep the original content will not be compiled.

5.androidmanifest file: manifest file for component lookup

6.classes.dex Files: All class collections, files executed by virtual machines

7,RESOURCES.ARSC: system Resource File index, contains some system information

The installation process is actually to put the apk file into a specific directory, and to generate files related to this application, application-level applications are generally placed under the Data/app, system-level applications placed under System/app.

Once there was an article explaining resources and Assetmanager, this time the path of the resource points to the APK file, you can get the resources needed. Dex is also a reason that Dex files are loaded through Dexclassloader, so that is, if we load the specified DEX file using the loader in the program, it can be dynamically loaded, and the Facebook sub-Dex package is also done in this way. As for why you want to divide multiple Dex files, here's an explanation:

Because an app will only have more and more features, but as the project grows larger and the number of Android methods cannot exceed 65K, if beyond, it will throw conversion to Dalvik format failed:unable to execute DEX: Method ID not in[0,0xffff]65536. Because the ID of the stored method in a Dex file is used for the short type data in an Android system, the number of methods in your Dex cannot exceed 65K, Before the 2.3 system, the virtual machine's memory was allocated only 5M, so remove some useless jar packages, set some properties to public, so you can remove the Get/set method to compress the number of methods.

--------------------------------------------------------------------------------------------------------------- ------------------------------------------

After the APK is finished, how is the apk packaged and generated?

First, Android's resources are packaged into the APK file via the packaging tool AAPT (Android Assest package tools). Before packaging, most text-formatted XML resource files are also compiled into binary-formatted XML resource files that are compiled from text format into binary format because:

1. The XML file in binary format takes up less space. This is because all XML element tags, property names, property values, and contents of the strings involved will be uniformly collected into a string resource pool, and will go heavy. There is this string resource pool where the original string is replaced with an integer value indexed to the string resource pool, which reduces the size of the file.

2. xml file parsing is faster in binary format. This is because the binary format XML element no longer contains string values, thus avoiding string parsing, which increases speed.

Compiling XML resource files from text format into binary format solves the problem of space occupancy and resolution efficiency, but for Android resource management frameworks This is only part of it, and the Android Resource Management framework has a more important task-to quickly find the corresponding resource based on the resource ID.

In order to enable users to have the best experience, in order to support the Android resource management framework to quickly locate the most matching resources, Android Resource Packaging tool AAPT in the process of compiling and packaging resources, the following two additional actions are performed:

1. Give each non-assets resource an ID value that is stored in the R.java file in the form of a constant.

2. Generate a RESOURCES.ARSC file that describes the configuration information for the resource with the ID value, and his content is equivalent to a resource Index table.

With the resource ID and Index table, the Android resource management Framework can quickly locate the most matching resources based on the current device configuration information.

============================================================

Understanding so much first, the workflow of AAPT packaging tools is not understood first.

How APK is Installed

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.