Details and use of the APK Optimizer tool zipalign

Source: Internet
Author: User

What is Zipalign?
Zipalign is a tool for organizing apk files on an Android platform, and it was first introduced in the SDK Software Development Kit for Android version 1.6. It is able to optimize packaged Android applications to make the interaction between the Android operating system and the application more efficient, which allows applications and the entire system to run faster. Application execution time with Zipalign is minimized, and when the device runs the APK application, it takes up less RAM (random access memory), We strongly recommend using the Zipalign tool on new and published programs to get an optimized version-even if your program was developed under an older version of Android. This article will explain how zipalign works and how to use it to optimize your app.

Zipalign How to optimize?

 Zipalign the uncompressed data in the APK file is aligned on a 4-byte boundary, the code that accesses the resource file is efficient when the resource file is aligned to a 4-byte boundary through memory mapping. After 4 byte alignment, the Android system can read the file by calling the Mmap function, and the process can operate on ordinary files like read-write memory, and the system shares the memory IPC to achieve higher performance on read resources. If the resource itself is not aligned, it must read them explicitly-the process will be slow and will cost extra memory.

Mmap system calls enable shared memory between processes by mapping the same common file. After the normal file is mapped to the process address space, the process can access the file like normal memory without having to call read (), write (), and so on.

The use of mmap in the program is a function of Mmap's "access to files like normal memory". When you want to access a file frequently, and the pointer moves back and forth, calling Mmap is much faster than using the regular method

Alignment on a 4-byte boundary means that the compiler has 4 bytes to read as a unit, so that the CPU is able to access the variable efficiently and quickly (not before).

The Davlik virtual machine in the Android system uses its own proprietary format DEX,DEX the structure is compact, in order to make the runtime better performance, you can further use "alignment" further optimization, but the size will generally increase.

An never-aligned apk reads a resource more slowly and spends more memory. The best case scenario is that the home program and the unaligned program start slower than the alignment (which is also the only visible effect). In the worst case scenario, installing an application that does not align resources increases the memory pressure and therefore causes the system to start and kill the process repeatedly. Eventually, the user abandons the use of a device that is so slow and consumes power.

How is zipalign used?

Using ADT:

    • If you use the Export Wizard, the ADT plugin in Eclipse (from Ver. 0.9.3 start) will automatically align the release package. Using the wizard, right-click the project properties and select "Android Tools" > "Export signed Application Package ...". Of course, you can also do this through the first page of the Androidmanifest.xml editor.

Using ant:

    • The ant compilation script (starting with Android 1.6) can align the package. Versions of the old platform cannot be aligned with the ant compilation script and must be manually aligned.
    • Starting with Android 1.6, when you compile in debug mode, Ant automatically signs the package to the alignment.
    • In release mode, if there is enough information to sign the package, Ant does the alignment because the alignment occurs after the signature. In order to be able to sign the package and then perform the alignment operation, Ant must know the location of the KeyStore and the name of key in Build.properties. The corresponding property names are Key.store and Key.alias. If these properties are empty, the signing tool prompts for the Store/key password during compilation, and the script performs the alignment of the signature and the APK file. If none of these properties are in place, the release package will not be signed and will naturally not be aligned.

Manual:

    • In order to be able to manually align packages, Android 1.6 and later SDKs have zipalign tools under the tools/folder. You can use it to align packages under any version. You must do this after signing the APK file, using the following command: Zipalign-v 4 source.apk destination.apk
    • To verify alignment:
      • The following commands are used to check whether the package is aligned: zipalign-c-V 4 application.apk

Details and use of the APK Optimizer tool zipalign

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.