zipalign

Stay organized with collections Save and categorize content based on your preferences.

zipalign is a zip archive alignment tool that helps ensure that all uncompressed files in the archive are aligned relative to the start of the file. This lets the files be accessed directly via mmap(2) , removing the need to copy this data in RAM and reducing your app's memory usage.

Use zipalign to optimize your APK file before distributing it to end users. If you build using Android Studio, this is done automatically. This documentation is for maintainers of custom build systems.

Caution: You must use zipalign at a specific point in the build process. That point depends on which app-signing tool you use:

  • If you use apksigner, zipalign must be used before the APK file has been signed. If you sign your APK using apksigner and make further changes to the APK, its signature is invalidated.
  • If you use jarsigner, zipalign must be used after the APK file has been signed.

To achieve alignment, zipalign alters the size of the "extra" field in the zip Local File Header sections. This process can also alter existing data in the "extra" fields.

Usage

If your APK contains shared libraries (.so files), use -p to ensure that they're aligned to a 4KiB page boundary suitable for mmap(2). For other files, whose alignment is determined by the mandatory alignment argument to zipalign, Android Studio aligns to 4 bytes on both 32-bit and 64-bit systems.

To align infile.apk and save it as outfile.apk:

zipalign -p -f -v 4 infile.apk outfile.apk

To confirm the alignment of existing.apk:

zipalign -c -v 4 existing.apk

Options

The following table lists the available zipalign options:

Option Description
-c Checks alignment only (does not modify file).
-f Overwrites existing output file.
-h Displays tool help.
-p Page-aligns uncompressed .so files.
-v Verbose output.
-z Recompresses using Zopfli.