اندازه APK برنامه ML Kit Android خود را کاهش دهید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
قبل از اینکه برنامهای را تولید کنید که از مدل کیت ML روی دستگاه استفاده میکند، توصیههای موجود در این صفحه را دنبال کنید تا حجم دانلود برنامه خود را کاهش دهید.
برنامه خود را به عنوان یک Android App Bundle بسازید
برنامه خود را بهعنوان یک Android App Bundle بسازید و اجرا کنید تا Google Play بتواند بهطور خودکار فایلهای APK را برای تراکم صفحهنمایش، معماری CPU و زبانهای خاص تولید کند. کاربران فقط باید فایلهای APK را دانلود کنند که با پیکربندی دستگاهشان مطابقت دارد و مهمتر از همه، کاربران فقط کتابخانههای کد بومی را دانلود کنند که با معماری دستگاهشان مطابقت دارد.
پیشرفته: ویژگی های اختیاری ML را به ماژول های ویژگی پویا منتقل کنید
اگر از ML Kit در یکی از ویژگی های برنامه خود استفاده می کنید که هدف اصلی آن نیست، برنامه خود را مجدداً تغییر دهید تا آن ویژگی و وابستگی های کیت ML آن به یک ماژول ویژگی پویا منتقل شود.
برای اینکه ویژگیهای ML Kit در یک ماژول ویژگی درخواستی کار کنند، در فایل build.gradle
apk پایه خود، وابستگی کتابخانه پشتیبانی از ویژگی پویا ML Kit playstore را شامل کنید.
dependencies {
// ...
implementation 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta2'
}
با انجام این کار، کاربران را از دانلود بیرویه مدلهای ML برنامهتان که میتواند بزرگ باشند، جلوگیری میکنید.
پیشرفته: باینری های استفاده نشده ML Kit را حذف کنید
کیت ML با پشتیبانی از معماری 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 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\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```"]]