تقليل حجم حِزم APK في تطبيق ML Kit لنظام التشغيل Android
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
قبل نشر تطبيق يستخدم نموذجًا من نماذج ML Kit على الجهاز في قناة الإصدار العلني، ننصحك باتّباع النصائح الواردة في هذه الصفحة لتقليل حجم تنزيل تطبيقك.
إنشاء تطبيقك على شكل حزمة تطبيق Android
أنشئ تطبيقك ونشِّره على شكل حزمة تطبيق Android ليتمكّن Google Play من إنشاء حِزم APK تلقائيًا لكثافات شاشة وبنيات وحدة معالجة مركزية ولغات محدّدة. ولن يضطر المستخدمون إلى تنزيل حِزم APK إلا إذا كانت متوافقة مع إعدادات أجهزتهم، والأهم من ذلك، لن يضطر المستخدمون إلى تنزيل مكتبات الرموز البرمجية الأصلية إلا إذا كانت متوافقة مع بنية أجهزتهم.
متقدّمة: نقل ميزات تعلُّم الآلة الاختيارية إلى وحدات الميزات الديناميكية
إذا كنت تستخدم ML Kit في إحدى ميزات تطبيقك التي لا تمثّل الغرض الأساسي منه، ننصحك بإعادة تصميم تطبيقك لنقل هذه الميزة وتبعياتها في ML Kit إلى وحدة ميزات ديناميكية.
لكي تعمل ميزات ML Kit في وحدة ميزة عند الطلب، يجب تضمين تبعية مكتبة دعم الميزات الديناميكية في Play Store الخاصة بـ ML Kit في ملف build.gradle
لحزمة APK الأساسية.
dependencies {
// ...
implementation 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta2'
}
ويؤدي ذلك إلى منع المستخدمين من تنزيل نماذج تعلُّم الآلة الخاصة بتطبيقك بدون داعٍ، والتي يمكن أن تكون كبيرة الحجم.
خيارات متقدّمة: استبعاد ملفات ML Kit الثنائية غير المستخدَمة
تم تصميم "حزمة تعلُّم الآلة" لتتوافق مع بنية 32 بت و64 بت. إذا كان تطبيقك يتوافق مع وضع 32 بت فقط، مثلاً لأنّك تستخدم مكتبة توفّر فقط ملفات ثنائية 32 بت، يمكنك استبعاد مكتبات ML Kit غير المستخدَمة من الإصدار على النحو التالي:
android {
defaultConfig {
ndk {
// Don't package arm64-v8a or x86_64
abiFilters 'armeabi-v7a', 'x86'
}
}
}
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-09-03 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-09-03 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eReduce your app's download size by building it as an Android App Bundle, enabling Google Play to deliver optimized APKs to users based on their device configurations.\u003c/p\u003e\n"],["\u003cp\u003eFor non-core ML features, leverage dynamic feature modules to deliver them on demand, minimizing the initial download size by excluding optional ML models.\u003c/p\u003e\n"],["\u003cp\u003eIf your app only supports 32-bit mode, exclude unused 64-bit ML Kit libraries to further reduce the app's size.\u003c/p\u003e\n"],["\u003cp\u003eTo enable ML Kit features in on-demand modules, include the \u003ccode\u003eplaystore-dynamic-feature-support\u003c/code\u003e library in your base APK's dependencies.\u003c/p\u003e\n"]]],[],null,["Before you deploy to production an app that uses an ML Kit on-device model,\nconsider following the advice on this page to reduce the download size of your\napp.\n\nBuild your app as an Android App Bundle\n\nBuild and deploy your app as an [Android App Bundle](//developer.android.com/guide/app-bundle/) so that Google\nPlay can automatically generate APKs for specific screen densities, CPU\narchitectures, and languages. Users will only have to download the APKs that\nmatch their device configuration, and most importantly, users only download the\nnative code libraries that match their device architecture.\n\nAdvanced: Move optional ML features to dynamic feature modules\n\nIf you use ML Kit in a feature of your app that isn't its primary purpose,\nconsider refactoring your app to move that feature and its ML Kit\ndependencies to a [dynamic feature module](//developer.android.com/studio/projects/dynamic-delivery#dynamic_feature_modules).\n\nIn order for ML Kit features to work in an on-demand feature module, in your base apk's `build.gradle` file,\ninclude the ML Kit playstore dynamic feature support library dependency. \n\n```carbon\ndependencies {\n // ...\n implementation 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta2'\n}\n```\n\nBy doing so, you prevent users from unnecessarily downloading your app's ML models, which can be\nlarge.\n\nAdvanced: Exclude unused ML Kit binaries\n\nML Kit is built with support for both 32-bit and 64-bit architectures. If\nyour app only supports 32-bit mode---for example, because you use a library\nthat only provides 32-bit binaries---you can exclude the unused ML Kit\nlibraries from your build: \n\n```carbon\nandroid {\n defaultConfig {\n ndk {\n // Don't package arm64-v8a or x86_64\n abiFilters 'armeabi-v7a', 'x86'\n }\n }\n}\n```"]]