zipalign
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
zipalign
เป็นเครื่องมือจัดตำแหน่งไฟล์ ZIP ที่ช่วยให้มั่นใจได้ว่าไฟล์ที่ไม่ได้บีบอัดทั้งหมด
ในที่เก็บถาวร
จะปรับแนวที่สัมพันธ์กับส่วนต้นของไฟล์ ซึ่งจะช่วยให้เข้าถึงไฟล์ได้โดยตรงผ่าน
mmap(2)
ทำให้ไม่จำเป็นต้องคัดลอกข้อมูลนี้ใน RAM และลดการใช้หน่วยความจำของแอป
ใช้ zipalign
เพื่อเพิ่มประสิทธิภาพไฟล์ APK ของคุณก่อนเผยแพร่
ผู้ใช้ปลายทาง หากคุณสร้างโดยใช้ Android Studio ซึ่งใช้ปลั๊กอิน Android Gradle (AGP)
ทำโดยอัตโนมัติ ในกรณีนี้ คุณควรใช้ zipalign
เพื่อยืนยันว่า APK
อยู่ในแนวเดียวกัน แต่คุณไม่จำเป็นต้องจัดวาง เอกสารนี้มีไว้สำหรับผู้ดูแล
ระบบการสร้างที่กำหนดเอง
ข้อควรระวัง: คุณต้องใช้ zipalign
ณ เวลาที่เฉพาะเจาะจงใน
ขั้นตอนการสร้าง จุดนี้ขึ้นอยู่กับเครื่องมือลงนามแอปที่คุณใช้ ดังนี้
-
หากคุณใช้
apksigner
, zipalign
จะต้องใช้ก่อนที่ไฟล์ APK จะได้รับการลงนาม หากคุณลงนาม
APK ที่ใช้ apksigner
และทำการเปลี่ยนแปลงเพิ่มเติมกับ APK ลายเซ็นของ APK จะใช้งานไม่ได้
-
หากคุณใช้
jarsigner
(ไม่แนะนำ) ต้องใช้ zipalign
หลังจากไฟล์ APK
ได้รับการลงนามแล้ว
เพื่อปรับให้ตรงกัน zipalign
จะปรับขนาดของช่อง "extra"
ในส่วนหัวของไฟล์ในเครื่อง ZIP
กระบวนการนี้ยังปรับเปลี่ยนข้อมูลที่มีอยู่ในช่อง "extra"
ได้ด้วย
การใช้งาน
หาก APK ของคุณมีไลบรารีที่แชร์ (.so
ไฟล์) ให้ใช้ -P 16
เพื่อให้มั่นใจว่ามิติข้อมูลอยู่ในแนวเดียวกับขอบเขตหน้า 16KiB ที่เหมาะกับ mmap(2)
ในอุปกรณ์ 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
ที่ใช้ได้
ตัวเลือก |
คำอธิบาย |
-ค |
ตรวจสอบเฉพาะการจัดแนวข้อความ (ไม่แก้ไขไฟล์) |
-f |
เขียนทับไฟล์เอาต์พุตที่มีอยู่ |
-ชม. |
แสดงความช่วยเหลือของเครื่องมือ |
-P <pagesize_kb> |
จัดเรียงไฟล์ .so ที่ไม่ได้บีบอัดให้เท่ากับขนาดหน้าที่ระบุใน KiB ตัวเลือกที่ใช้ได้
สำหรับ <pagesize_kb> เท่ากับ 4, 16 และ 64 |
-P |
ไฟล์ .so ที่จัดอยู่ในแนวเดียวกับหน้า 4KiB ที่ไม่ได้บีบอัด ขอแนะนำให้ใช้
-P 16 แทน เนื่องจาก -p เลิกใช้งานแล้ว |
-v |
เอาต์พุตแบบละเอียด |
-z |
บีบอัดอีกครั้งโดยใช้ Zopfli |
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 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. |"]]