Analysis: Android system after the brush, the first boot started very slow reason

Source: Internet
Author: User

In the process of doing Android kernel development, we will find that every time the system source code, burned to the device/mobile phone, the first start will be very slow and slow, to several minutes or even more than 10 minutes, why this phenomenon? What is the difference between the first boot and the back start after the system brushes?

To answer this question, first we need to know about the Android Dalvik virtual machine, as well as the Dalvik-cache.

Because of the limited memory of the embedded device, the weak CPU processor, the power-sensitive, and so on, Google did not use the standard JVM virtual machine, but instead developed the Dalvik virtual machine for Android alone.

The Dalvik virtual machine is very different from the JVM virtual machine, which runs an optimized and compressed Dex bytecode that is not the same as the standard jar bytecode, takes up less space, and can be further optimized for Android The SDK specifically provides the DX tool to convert the traditional Java bytecode into the Dex bytecode that the Dalvik virtual machine can run, which is done when the program is compiled, which is why we can use Java to write to run on Android Dalvik the reason for the virtual machine's program. For this process, here is a more intuitive one:

In order to facilitate the spread, the Android SDK will be compiled by the program Dex bytecode files, resource files, Lib library, Androidmanifest.xml and other files packaged together compressed into the APK file (actually a zip compressed file), so, The installation and uninstallation of the APK is actually the process of extracting the files from the ZIP archive and analyzing the copy and optimization.

Since Dex bytecode is in the APK compression package, it is obviously inefficient to extract Dex bytecode from the APK file every time the program starts, so the Android system designs the following strategy:

(1) Create a "Dalvik-cache" folder specifically for Dex bytecode, located in/data/dalvik-cache

(2) The first time the system starts, scan all pre-installed apk files, extract the program's Dex bytecode, after optimization, stored in the Dalvik-cache directory

(3) Each time the new apk is installed, the Dex bytecode is also extracted, optimized to be placed in the Dalvik-cache directory

(4) After the user clicks on the app icon, the optimized Dex bytecode is loaded directly from the Dalvik-cache directory, so the program can be started quickly.

Understanding the above principles, the problems discussed in this article will be solved, the Android system after the first boot start, you need to scan all the pre-installed apk files, extracted Dex bytecode, optimized and copied to the/data/dalvik-cache cache directory, so, The first boot time can be significantly higher.

Recommended by US:

    • Technology Blog: How to encrypt a mobile app encryption issue. What about the Dex file?
    • Technology Blog: What are the Android app hack technologies? How to Anti- decompile
    • Technology Blog: How to prevent two times packaging, love encryption reinforcement apk anti -hack

Analysis: Android system after the brush, the first boot started very slow reason

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.