zipalign
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
zipalign
は zip アーカイブ アライメント ツールです。アーカイブ内のすべての非圧縮ファイルを、ファイルの先頭を基準として揃えるようにします。これらのファイルに mmap(2)
から直接アクセスできるようになるため、このデータを RAM にコピーする必要がなくなり、アプリのメモリ使用量を減らせます。
APK ファイルをエンドユーザーに配布する前に zipalign
を使用して最適化します。Android Studio(Android Gradle プラグイン(AGP)を使用している)を使ってビルドした場合は、自動的に最適化されます。この場合、引き続き zipalign
を使用して APK のアライメントが調整されていることを確認できますが、アライメントを調整する必要はありません。このドキュメントは、カスタム ビルドシステムの管理者を主に対象としています。
注意: ビルドプロセスの特定の時点で zipalign
を使用する必要があります。この点は、使用するアプリ署名ツールによって異なります。
-
apksigner
を使用する場合は、APK ファイルを署名する前に zipalign
を使用する必要があります。apksigner
を使用して APK に署名した後で APK を変更すると、その署名は無効になります。
-
jarsigner
を使用する場合は(推奨されません)、APK ファイルの署名後に zipalign
を使用する必要があります。
アライメントは、zipalign
が zip ローカル ファイル ヘッダー セクションの "extra"
フィールドのサイズを変更することで行われます。このプロセスでは、"extra"
フィールドの既存のデータを変更することもできます。
使用方法
APK に共有ライブラリ(.so
ファイル)が含まれている場合は、-P 16
を使用します。
mmap(2)
に適した 16 KiB ページ境界に沿って配置されるようにします。
16 KiB と 4 KiB の両方のデバイスで保存されています。それ以外のファイルについては、
zipalign
に対する必須のアライメント引数。4 バイトにアライメントする必要があります。
32 ビットと 64 ビットの両方のシステムに対応しています。
infile.apk
のアライメントを調整して outfile.apk
として保存するには:
zipalign -P 16 -f -v 4 infile.apk outfile.apk
existing.apk
の配置を確認するには、次のコマンドを使用します。
zipalign -c -P 16 -v 4 existing.apk
オプション
次の表に、使用可能な zipalign
オプションを示します。
オプション |
説明 |
-c |
配置のみを確認します(ファイルは変更しません)。 |
-f |
既存の出力ファイルを上書きします。 |
-h |
ツールのヘルプを表示します。 |
-P <ページサイズ_kb> |
非圧縮 .so ファイルを、指定された KiB 単位でページサイズに揃えます。有効なオプション
<pagesize_kb> は 4、16、64 です。 |
-p |
4 KiB は、非圧縮の .so ファイルをページ調整します。Google Cloud コンソールから
-p が非推奨になったため、代わりに -P 16 を使用します。 |
-v |
詳細な出力を行います。 |
-z |
Zopfli を使用して再圧縮します。 |
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# zipalign\n\n`zipalign` is a zip archive alignment tool that helps ensure that all uncompressed files\nin the archive\nare aligned relative to the start of the file. This lets the files be accessed directly via\n[mmap(2)](https://man7.org/linux/man-pages/man2/mmap.2.html)`\n`, removing the need to copy this data in RAM and reducing your app's memory usage.\n\nUse `zipalign` to optimize your APK file before distributing it to\nend users. If you build using Android Studio, which uses the Android Gradle plugin (AGP), this is\ndone automatically. In this case, you should still use `zipalign` to verify that the APK\nis aligned, but you don't need to align it. This documentation is mainly for maintainers of\ncustom build systems. \n\n**Caution:** You must use `zipalign` at a specific point in\nthe build process. That point depends on which app-signing tool you use:\n\n- If you use [apksigner](/studio/command-line/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.\n- If you use [jarsigner](//docs.oracle.com/javase/tutorial/deployment/jar/signing.html) (not recommended), `zipalign` must be used **after** the APK file has been signed.\n\nTo achieve alignment, `zipalign` alters the size of the `\"extra\"` field in the zip **Local File Header**\nsections. This process can also alter existing data in the `\"extra\"` fields.\n\nUsage\n-----\n\nIf your APK contains shared libraries (`.so` files), use `-P 16`\nto ensure that they're aligned to a 16KiB page boundary suitable for `mmap(2)`\nin both 16KiB and 4KiB devices. For other files, whose alignment is determined by the\nmandatory alignment argument to `zipalign`, should be aligned to 4 bytes\non both 32-bit and 64-bit systems.\n\nTo align `infile.apk` and save it as `outfile.apk`: \n\n```\nzipalign -P 16 -f -v 4 infile.apk outfile.apk\n```\n\nTo confirm the alignment of `existing.apk`, use the following command. \n\n```\nzipalign -c -P 16 -v 4 existing.apk\n```\n\n### Options\n\nThe following table lists the available `zipalign` options:\n\n| Option | Description |\n|--------------------|-------------------------------------------------------------------------------------------------------------------------|\n| -c | Checks alignment only (does not modify file). |\n| -f | Overwrites existing output file. |\n| -h | Displays tool help. |\n| -P \\\u003cpagesize_kb\\\u003e | aligns uncompressed `.so` files to the specified page size in KiB. Valid options for `\u003cpagesize_kb\u003e` are 4, 16, and 64. |\n| -p | 4KiB page-aligns uncompressed `.so` files. It is recommended to use `-P 16` instead, as `-p` is deprecated. |\n| -v | Verbose output. |\n| -z | Recompresses using Zopfli. |"]]