How to use zipalign tool to optimize

One, zipalign introduction     

The Android SDK includes a "zipalign" tool that can optimize packaged applications. Run zipalign on your application to make the interaction between Android and the application more efficient at runtime. Therefore, this approach allows applications and the entire system to run faster. We strongly recommend using the zipalign tool on new and released programs to get the optimized version.

    According to the description of the official document, the application data in the Android system is stored in its APK file and can be accessed by multiple processes at the same time. The installation process includes the following steps:

1. Installer obtains the permissions information associated with the current application through the manifest file of each apk.

2. The Home application reads the Name and Icon of the current APK.

3. The System server will read some information related to the operation of the Application, such as obtaining and processing notifications requests of the Application, etc.

4. Finally, the content contained in the APK is not only limited to the current Application, but also can be called by other Applications, improving the reusability of system resources.

       The most fundamental purpose of zipalign optimization is to help the operating system to index resources more efficiently according to the request, and to unify the resource-handling code to limit the Data structure alignment (DSA) to 4-byte boundaries. If you are exposed to the content of Data structure alignment for the first time, it is strongly recommended to search for more related content to fully understand the ultimate purpose of doing so. This is also the key to understanding the working principle of zipalign. If the alignment standard is not adopted, the processor cannot accurately and quickly locate the relevant resources in the memory address.

2. How to use

Method 1: Use the command line

1. Find the zipalign.exe file in the tools folder of the Android SDK .
2. Copy the apk you want to optimize to the tools folder you unzipped.
Start -> Run -> CMD to bring up the command line window
In the command line, enter the folder path you decompressed \zipalign -v 4 The name of the apk you want to optimize.apk The name of the optimized apk.apk
例如C:\Windows\android-sdk-windows\tools\zipalign -v 4 Example.apk Example.1.apk

Where -v stands for detailed output, and 4 stands for alignment to 4 bytes.

Method 2: Configure in build.gradle

release {     //Zipalign optimization

    zipAlignEnabled true
}

Guess you like

Origin blog.csdn.net/hello_1995/article/details/52870573