Android APK installation process learning notes, androidapk

Source: Internet
Author: User

Android APK installation process learning notes, androidapk
1. What is APK?

APK, which is the Android Package and Android installation Package. The installation files on different platforms are in different formats. Similar to Windows, the installation packages are in binary exe format, while Mac installation packages are in dmg format. The APK can be installed on Android. The essence of the APK is a Zip package, but the suffix is changed to apk, which packages the class compiled by the source code. dex, some image visual screen resource files, and some Native library files. The biggest difference between an APK file and a Zip file is that an APK contains a signature file, which is used to ensure the security of the installation package.

2. What are DEX files and ODEX files?

The Java card Platform runs class files compiled by source code on virtual machines on different platforms, and the virtual machines shield the differences between different platforms. However, the Android system optimizes the Dalvik Virtual Machine for handheld devices, including:
(1) Optimize the original class file, for example, merge the redundant constant information to provide virtual machine resolution efficiency;
(2) modify the stack-based data structure of JVM runtime to the register-based data structure of Dalvik. The data access mode is faster and the running efficiency is higher.
In this case, some of the original. class files are not applicable. Therefore, the dex file format appears, which is the file generated after source code compilation. It is an integral part of APK. The ODEX file is generated by Dalvik after extracting the executable class. dex file from the dex file and storing it locally. Because the Android system cannot directly run the APK file, you need to decompress it and find the class. dex file before it can run. Therefore, you can extract it locally during installation to increase the application startup speed. In addition to this reason. when dex is converted to an ODEX file, it is also optimized based on the current system (directly copying to another system may not be able to run). The file size will be reduced, and the ODEX file is more difficult to decompile than the DEX file, this also improves security to a certain extent. Therefore, ODEX is used for some system pre-installation or system-level applications. Generally, ODEX does not run directly. When Dalvik runs ODEX, it needs to be optimized through JIT to improve the running efficiency. JIT is a process of synchronously converting bytecode into machine code at runtime. Dalvik runs the converted machine code directly, which causes some memory and time overhead, in some cases, the system performance is improved. (Some dynamic compilers may compile based on experience or try to optimize this process. The more times it runs, the better the optimization effect ).

3. What is an OAT file?

An OAT file is a binary file that can be run by ART. It contains the DEX file and compiled Local Machine command files. The file format is similar to network data packets, contains the file header and file body. The oatdata, oatexec, and oatlastword fields in the file header respectively describe the DEX file location and the start and end locations of Local Machine commands. Because the OAT file contains the DEX file, it occupies more space than the ODEX file. Because it is processed by ART during installation, the OAT file can be directly run without processing, it does not have the process of converting from bytecode to machine code, so it runs faster. It can be understood that during JIT optimization, the parsing is advanced from the runtime to the installation, and the installation slows down and runs faster.

4. What are Dalvik and ART?

Dalvik and ART are both Android runtime environments, but because Dalvik has some shortcomings, ART replaces Dalvik on a high-version mobile phone. Dalvik and ART are Java virtual machines implemented on the Android platform. Used to parse DEX files, ODEX files, and OAT files. ART is the Android Runtime. During Android running, because the Android system runs on different devices and the underlying hardware is different, the Linux system shields some details of these systems, however, it is too difficult to develop applications directly on Linux, and the implementation cost is too high. To avoid Linux details, Google created Dalvik and ART and encapsulated Linux,
With the integrated development environment SDK provided by Google, you can easily develop applications. The relationship between Dalvik and ART is that ART is used to replace Dalvik. Now, the market share of ART has exceeded 70%. ART is the running mode of the Android application. In this mode, the Android application is pre-compiled after it is installed, convert the bytecode in the application installation package to the machine language and store it locally (the system can only run binary programs). In this way, the application can directly execute these binary programs when running. Compared with Dalvik, Dalvik stores the bytecode directly after the application is installed. During each running, the Code must be compiled into a machine language, it is slower than ART. In this case, the application occupies a larger space and the installation time is longer. However, this is worthwhile for applications that are frequently used.

5. How is APK installed?

The source Code of the program is first compiled into the DEX file through the SDK, The DEX file, some resource files (images, videos, etc.), and Native Code (C language, etc. so file) is directly packaged into the APK. The APK installation process is actually the process of extracting the installation package. Decompress resource files and binary libraries and store them locally. The DEX files are not only extracted, but are processed in different ways according to the operating environment of the system, files in different formats are stored locally, waiting for the program to start calling. This completes the application installation process.

 

Summary:APK is the Android installation package. Dalvik and ART are both Android runtime environments. ART replaces Dalvik on a high-version mobile phone. The dex file is a package generated after source code compilation and is an integral part of the APK. During installation, Dalvik decompress the class. dex file that can be executed in the dex file and stores it locally as an ODEX file. The file generated by ART is OAT.

Dalvik and ARTComparison:
(1) Dalvik and ART are Java virtual machines implemented on the Android platform. Used to parse DEX files, ODEX files, and OAT files.
(2) The ART parsing mode is that after the Android application is installed, a pre-compilation is performed to convert the bytecode in the application installation package to the machine language and store it locally.
(3) The Dalvik parsing mode stores the bytecode directly after the application is installed. During each running, the Code must be compiled into a machine language.
(4) when running the program, Dalvik is slower than ART. After ART is installed, the application occupies more space and the installation time is long.


Comparison between ODEX files and OAT files:
(1) Dalvik converts the APK content to ODEX, and ART converts it to OAT.
(2) ODEX needs to be optimized through JIT to improve operation efficiency.
(3) OAT contains DEX files and compiled Local Machine command files, which occupy a larger space than ODEX files and can be run directly without processing. The operation speed is fast.


Article: http://mp.weixin.qq.com/s/37wjSQs1HWVfX0xL27NjBg

Related Article

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.