zipalign
Optimize Android APK file alignment
TLDR
SYNOPSIS
zipalign [-c] [-f] [-P pagesizekb] [-v] [-z] alignment input.apk [output.apk_]
DESCRIPTION
zipalign is an archive alignment tool from the Android SDK that optimizes APK files by ensuring all uncompressed data starts at a particular byte alignment relative to the file start. This optimization allows Android to memory-map files directly from the APK, reducing RAM usage and improving app launch performance.The tool works by adjusting the extra field padding in ZIP entries so that file data boundaries align to the specified value (always 4 bytes for APKs). This allows the Android runtime to access uncompressed resources with mmap() instead of copying them into the heap.The correct order of operations depends on the signing tool used. When using apksigner, run zipalign before signing. When using jarsigner, run zipalign after signing. For Android App Bundles (AAB), zipalign is not needed as Google Play handles optimization during APK generation.The tool is located in the build-tools directory of the Android SDK (e.g., `$ANDROID_HOME/build-tools/34.0.0/zipalign`).
PARAMETERS
-c
Check alignment only (confirm mode). Does not modify the file.-f
Force overwrite of existing output file.-P pagesizekb_
Page-align uncompressed .so files to the specified page size in KiB. Valid values are 4, 16, or 64. Use -P 16 for compatibility with both 4 KiB and 16 KiB page size devices.-p
Deprecated. Legacy 4 KiB page alignment for .so files. Use -P 16 instead.-v
Verbose output, showing alignment status for each file in the archive.-z
Recompress using Zopfli for smaller file size (slower).-h
Display help information.alignment
Byte alignment boundary. Always use 4 for APK files.input.apk
The input APK file to process.output.apk
The output aligned APK file (required unless using -c).
CAVEATS
The order relative to signing depends on the tool: run zipalign before apksigner but after jarsigner. Using -P 16 is required for apps targeting Android 15+ to properly align native libraries for 16 KiB page size devices. Does not work with Android App Bundles (AAB). The alignment value should always be 4 for APKs. Zipalign does not perform signing. The lowercase -p flag is deprecated in favor of -P.
HISTORY
zipalign was introduced by Google as part of the Android SDK tools. It became part of the standard Android build process to ensure optimal runtime performance. Starting November 2025, Google Play requires all apps targeting Android 15+ on 64-bit devices to support 16 KiB page sizes, making the -P 16 flag essential for apps with native libraries.
SEE ALSO
apksigner(1), aapt(1), aapt2(1), adb(1), bundletool(1)
