Linux command
zipalign 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Align an APK file
zipalign -P 16 -f -v 4 [input.apk] [output.apk]
Verify alignment
zipalign -c -P 16 -v 4 [path/to/file.apk]
Align with basic 4-byte alignment
zipalign -v 4 [input.apk] [output.apk]
Force overwrite
zipalign -f 4 [input.apk] [output.apk]
Check alignment without verbose output
zipalign -c 4 [path/to/file.apk]
说明
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`).
参数
- -c
- Check alignment only (confirm mode). Does not modify the file.
- -f
- Force overwrite of existing output file.
- -P _pagesize_kb_
- 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.
FAQ
What is the zipalign command used for?
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`).
How do I run a basic zipalign example?
Run `zipalign -P 16 -f -v 4 [input.apk] [output.apk]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c do in zipalign?
Check alignment only (confirm mode). Does not modify the file.