LinuxCommandLibrary

zipalign

Optimize Android APK file alignment

TLDR

Align an APK file with 4-byte alignment

$ zipalign -v 4 [input.apk] [output.apk]
copy
Verify alignment of an APK
$ zipalign -c -v 4 [path/to/file.apk]
copy
Align with page alignment (required for Android 11+)
$ zipalign -p -v 4 [input.apk] [output.apk]
copy
Force overwrite existing output file
$ zipalign -f 4 [input.apk] [output.apk]
copy
Align with zip-align for shared libraries
$ zipalign -p -f -v 4 [input.apk] [output.apk]
copy
Check alignment without verbose output
$ zipalign -c 4 [path/to/file.apk]
copy

SYNOPSIS

zipalign [-c] [-f] [-p] [-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.
Zipalign must be run after signing the APK with apksigner or jarsigner. Running zipalign before signing would invalidate the signature since it modifies the ZIP structure. 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
Page-align uncompressed .so files. Required for Android 11 (API 30) and higher for optimal memory mapping.
-v
Verbose output, showing alignment status for each file in the archive.
-z
Recompress using Zopfli for smaller file size (slower).
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

Must be run after APK signing, not before. Using -p flag is required for apps targeting Android 11+ to properly align native libraries for memory mapping. Does not work with Android App Bundles (AAB). The alignment value should always be 4 for APKs. Zipalign does not perform signing.

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. With Android 11 in 2020, Google added the requirement for page-aligned native libraries (-p flag) to support more efficient memory mapping on newer devices.

SEE ALSO

apksigner(1), aapt(1), aapt2(1), adb(1), bundletool(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community