zipalign
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
zipalign
은 보관 파일 중 압축되지 않은 모든 파일이 파일 시작 부분을 기준으로 정렬되도록 하는 ZIP 파일 정렬 도구입니다. 이렇게 하면 mmap(2)
를 통해 이러한 파일에 직접 액세스할 수 있으므로 RAM에 데이터를 복사할 필요가 없고 앱 메모리 사용량을 줄일 수 있습니다.
APK 파일을 최종 사용자에게 배포하기 전에 zipalign
을 사용하여 최적화합니다. Android Gradle 플러그인(AGP)을 사용하는 Android 스튜디오를 사용하여 빌드하는 경우 자동으로 실행됩니다. 이 경우에도 zipalign
을 사용하여 APK가 정렬되었는지 확인해야 하지만 정렬할 필요는 없습니다. 이 문서는 맞춤 빌드 시스템의 운영자를 위해 작성되었습니다.
주의: zipalign
은 빌드 프로세스의 특정 지점에서 사용해야 합니다. 이 지점은 사용하는 앱 서명 도구에 따라 다릅니다.
-
apksigner
를 사용하는 경우 APK 파일 서명 전에 zipalign
을 사용해야 합니다. apksigner
를 사용하여 APK에 서명하고 APK를 추가로 변경하면 서명이 무효화됩니다.
-
jarsigner
를 사용하는 경우(권장하지 않음) APK 파일에 서명한 후에 zipalign
을 사용해야 합니다.
정렬을 위해 zipalign
은 zip Local File Header 섹션에 있는 "extra"
필드 크기를 변경합니다. 이 프로세스는 "extra"
필드의 기존 데이터를 변경할 수도 있습니다.
사용
APK에 공유 라이브러리 (.so
파일)가 포함된 경우 -P 16
를 사용합니다.
mmap(2)
에 적합한 16KiB 페이지 경계에 맞게 정렬되도록 합니다.
16KiB와 4KiB 기기에서 모두 지원됩니다. 정렬은
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 <pagesize_kb> |
압축되지 않은 .so 파일을 KiB 단위의 지정된 페이지 크기에 맞춥니다. 유효한 옵션
<pagesize_kb> 는 4, 16, 64입니다. |
-p |
압축되지 않은 .so 파일을 4KiB로 페이지 정렬합니다. kubectl run을 사용하여
-p 가 지원 중단되었으므로 -P 16 를 대신 사용하세요. |
-v |
상세 출력을 표시합니다. |
-z |
Zopfli를 사용하여 다시 압축합니다. |
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 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. |"]]