Detailed explanation of Android APK optimization tool zialign

The Android SDK includes a new tool ziphalign for optimizing APK. It improves the interaction efficiency between the optimized applications and the Android system (as the saying goes: "build the road before you get rich", and the Android team has rebuilt a highway between applications and the Android system), which can greatly improve the running speed of the whole system. The Android team strongly recommends that developers use the zippalign optimization tool before publishing new apps, and for apps that have been published but are not limited to the system version, it is recommended to replace the existing version with the optimized APK.

In the following content, we will introduce ziphalign from three aspects:

1. How to optimize zip align

2. How to use zip align

3. Reasons for using zip align

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

1. The installer obtains the permissions information associated with the current application through the manifest file of each APK.

2. The home application reads the name, icon and other information of the current APK.

3. System server will read some information related to application operation, such as obtaining and processing application notifications requests.

4. Finally, the content contained in APK is not limited to the current application, but can be called by other applications to improve the reusability of system resources.

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

In the current system, fallback mechanism is used to deal with applications that do not apply DSA standard, which really greatly facilitates ordinary developers without paying attention to cumbersome memory operation. However, on the contrary, such an application will bring some trouble to ordinary users, which will not only affect the operation efficiency of the program, but also reduce the overall execution efficiency of the system, occupy a lot of unnecessary memory resources, and even consume a certain battery life.

There are three methods to apply align operation in the Android SDK:

1. Using ADT:

From ADT 0.9 From version 3, you can automatically align the published application packages through the Export Wizard. Setting method: right click Project and select "Android Tools > exportsigned application package...". Or you can go directly to Android manifest XML.

2. Using ant:

For application packages with API level greater than or equal to 4, align can be optimized directly through ant build script. However, when the API level is less than 4, you can only use manual align optimization.

By default, when you run debug packages (API level > = 4) using ant build script, align optimization will be automatically performed.

For release packages. When using ant build script to perform align optimization, you first need to have enough information to sign packages. Align optimization cannot be performed until signing is completed. Learn how to sign packages through official documents.

3. Manually perform align Optimization:

Use the zippalign tool under the tools folder. First call out the CMD command line, and then execute: zialign - V 4 source apk androidres. apk。 This method is not limited by API level and can perform align optimization on any version of APK.

At the same time, you can use the zippalign tool to check whether the current APK has performed align optimization. Command: ziphalign - C - V 4 Android apk

Once again, remind developers to immediately apply the zippalign tool to forcibly optimize the published application packages and let your users use the latest version.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>