محاذاة إلى الخلف
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
إنّ zipalign
هي أداة لمحاذاة الأرشفة بتنسيق ZIP التي تساعد في ضمان تحميل جميع الملفات غير المضغوطة.
في الأرشيف
تتم محاذاتها مع بداية الملف. يتيح ذلك الوصول إلى الملفات مباشرة عبر
mmap(2)
، ما مِن حاجة إلى نسخ هذه البيانات إلى ذاكرة الوصول العشوائي (RAM) والحدّ من استخدام تطبيقك للذاكرة.
استخدام zipalign
لتحسين ملف APK قبل توزيعه على
المستخدمين النهائيين. إذا كنت تستخدم الإصدار Android Studio الذي يستخدم المكوّن الإضافي لنظام Gradle المتوافق مع Android (AGP)، فهذا يعني
القيام به تلقائيًا. وفي هذه الحالة، يجب مواصلة استخدام zipalign
للتحقّق من أنّ حزمة APK.
موقعك، ولكنك لست بحاجة إلى محاذاته. هذا الوثائق مخصص بشكل أساسي للمحافظين على
وأنظمة التصميم المخصصة.
تنبيه: يجب استخدام zipalign
في نقطة محدّدة من
عملية التصميم. تعتمد هذه النقطة على أداة توقيع التطبيق التي تستخدمها:
-
إذا كنت تستخدم
apksigner
وzipalign
يجب استخدامه قبل توقيع ملف APK. إذا وقّعت على
حزمة APK تستخدم apksigner
وتُجري تغييرات إضافية على حزمة APK، تم إبطال توقيعها.
-
في حال استخدام
jarsigner
(لا ننصح بهذا الخيار)، يجب استخدام zipalign
بعد توفُّر ملف APK
المشروع.
لتحقيق المحاذاة، يغيّر zipalign
حجم الحقل "extra"
في عنوان الملف المحلي المضغوط
الأقسام. يمكن أن تؤدي هذه العملية أيضًا إلى تغيير البيانات الحالية في حقول "extra"
.
الاستخدام
إذا كانت حزمة APK تحتوي على مكتبات مشتركة (.so
ملف)، استخدِم -P 16
.
للتأكد من محاذاتها مع حدود صفحة يبلغ حجمها 16 كيلوبايت، وهي مناسبة للسمة mmap(2)
في أجهزة 16 كيلوبايت و4 كيلوبايت. بالنسبة إلى الملفات الأخرى، التي يتم تحديد محاذاتها بواسطة
وسيطة محاذاة إلزامية إلى 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
" المتاحة:
Option |
الوصف |
-ج |
يتحقق من المحاذاة فقط (لا يؤدي إلى تعديل الملف). |
-f |
يؤدي إلى استبدال ملف الإخراج الحالي. |
-س |
عرض مساعدة الأداة |
-P <pagesize_kb> |
لمحاذاة ملفات .so غير المضغوطة مع حجم الصفحة المحدّد بالكيلوبايت. الخيارات الصالحة
لـ <pagesize_kb> تكون 4 و16 و64. |
-p |
4 كيلوبايت تتم محاذاة ملف .so غير مضغوط. يُنصح باستخدام
-P 16 بدلاً من ذلك، نظرًا لإيقاف -p نهائيًا. |
-v |
النتائج المطوّلة. |
-z |
يعيد الضغط باستخدام Zopfli. |
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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. |"]]