Android APK installation Process Learning notes

Source: Internet
Author: User

1. What is APK

APK, which is the Android Package,android installation package. The installation file formats for different platforms are different, similar to the Windows installation package is the binary EXE format, the MAC installation package is the DMG format. APK can be installed on Android, the essence of the APK is a zip compression package, but the suffix is modified to APK, which packaged the source code compiled class.dex, some picture video resource files and some native library files. The biggest difference between the apk file and the zip file is that the APK contains the signature file, which is used to ensure that the package security is not modified.

2. What is a Dex file and a Odex file

The Java Card platform is a class file compiled by source code that runs on virtual machines of different platforms, and the virtual machine masks the differences between different platforms. However, due to the Android system for handheld devices, the Dalvik virtual machine is optimized, mainly including:
(1) The original class file is optimized, for example, the constant redundancy information is merged to provide virtual machine resolution efficiency;
(2) Modify the stack-based data structure of the JVM runtime to Dalvik Register-based, data access is faster and more efficient.
In this case, the original. class file is somewhat inappropriate, so there is the Dex file format, which is a file that is packaged and generated after the source code is compiled. It is an integral part of the APK. The Odex file is Dalvik after the executable file in the Dex file is extracted from the Class.dex file and stored locally after it is generated. Because the Android system cannot run the APK file directly, it needs to be unpacked and found Class.dex file before it can run, so it can be removed and put on-premises when installed, which will increase the application startup speed. In addition to this reason, In fact, in the process of converting Class.dex to Odex files, it is also optimized according to the current system (copying directly to other systems may not be possible), the file size is reduced, the Odex file is more difficult to decompile than the Dex file, which also improves the security to some extent, so in some systems pre-installed or system-level applications mostly use OD Ex Optimization. General Odex do not run directly, in Dalvik run Odex, need to be optimized by JIT, improve the efficiency of operation. JIT is a process of synchronizing bytecode into machine code at run time, Dalvik directly run the converted machine code, which can lead to some memory and time overhead, but overall, in some cases, it will improve the performance of the system. (some dynamic compilers, which may be based on experience or attempt to compile, optimize this process, the more likely the number of runs, the better the optimization effect).

3. What is an oat file

The oat file is an art run file, a binary executable file that contains the Dex file and the compiled local machine instruction file in a file format similar to a network data packet, containing the file header and file body, the oatdata of the file header, The Oatexec and Oatlastword fields describe the Dex file location and the start and end location of the local machine instruction, respectively. Because the oat file contains the Dex file, it takes up more space than the Odex file, and because it has been processed by art during installation, art loads the oat file without having to be processed to run directly, without the process of converting from bytecode to machine code, so it runs faster. It can be understood that the optimizations for JIT are resolved from run-time until the installation is resolved, the installation slows down, and the run becomes faster.

4. What is Dalvik and art

Dalvik and art are both Android-run environments, but because of Dalvik, art is replacing Dalvik on a higher-version phone. Dalvik and art are Java virtual machines implemented by the Android platform. Used to parse Dex files, odex files, and oat files. Art is the Android Runtime,android runtime, because the Android system runs on different devices, the underlying hardware is different, the Linux system masks some of these system details, but it is too difficult to develop the application directly on Linux, the implementation costs are too high, To block the details of Linux, Google created Dalvik and art to encapsulate Linux again, so that
With the integrated development Environment SDK provided by Google, it's easy to develop apps, and Dalvik's relationship to art is that art is replacing Dalvik, and art is now taking up more than 70% of the market. Art is the operating mode of Android applications, in which Android apps are pre-compiled once installed, and the bytecode in the app installation package is converted to machine language stored locally (the system can only run binaries), so that the application can execute these binaries directly at run time. Compared to Dalvik, the Dalvik approach is to store the bytecode directly after the application is installed, and to compile the code into machine language each time it is run, which is slower than art when running the program. This has resulted in more space for post-installation applications and longer installation times, but it is worthwhile for frequently used applications.

How is the 5.APK installed?

The source code of the program, first compiled by the SDK to Dex files, Dex files and some resource files (pictures, videos, etc.), Native Code (c language, such as compiled. so files) will be directly packaged into the APK. The process of installing the APK is actually the process of unpacking the package. Resource files, binary libraries and so on after decompression directly stored in the local, Dex files not only decompression, according to the operating environment of the system, using different processing methods, are processed into different formats of files stored locally, waiting for the program to start the call, so that the application installation process completed.

Summary: APK is an Android installation package, Dalvik and art are all Android operating environments, art is to replace Dalvik on a higher version of the phone. The Dex file is the source code after the compilation of the package generated files, is a part of the APK, the installation of Dalvik Dex files in the executable file Class.dex extracted files stored locally is Odex file. The files generated by the art run are oat.

comparison of Dalvik and art:
(1) Dalvik and art are Java virtual machines implemented by the Android platform. Used to parse Dex files, odex files, and oat files.
(2) Art analytic mode is an Android app that, once installed, will be pre-compiled to convert the bytecode in the app installation package into machine language stored locally.
(3) Dalvik parsing mode is to store the bytecode directly after the application is installed, and the code needs to be compiled into machine language each time it is run.
(4) When running the program, Dalvik is slower than art, the art after installation occupies more space, long installation time.


Odex file Compare to oat file:
(1) Dalvik the contents of the APK into Odex,art to convert it into oat.
(2) Odex needs to be optimized by JIT to improve operation efficiency.
(3) oat contains DEX files and compiled local machine instruction files, larger than Odex files occupy space, do not need to be processed to run directly, run fast.


Study article: Http://mp.weixin.qq.com/s/37wjSQs1HWVfX0xL27NjBg

Android APK installation process Learning notes

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.