ML Kit Android アプリの APK のサイズを小さくする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ML Kit デバイスモデルを使用するアプリを本番環境にデプロイする前に、このページの以下の推奨事項に従って、アプリのダウンロード サイズを小さくすることを検討してください。
Android App Bundle としてアプリをビルドする
Android App Bundle としてアプリをビルドしてデプロイすると、特定の画面解像度、特定の CPU アーキテクチャ、特定の言語用の APK が Google Play によって自動的に生成されるようになります。これにより、ユーザーは自分の端末の構成に適合する APK のみをダウンロードできるようになります。また、非常に重要な点として、ユーザーは自分の端末のアーキテクチャに適合するネイティブ コード ライブラリのみをダウンロードするだけで済みます。
高度な設定: オプションの ML 機能を動的機能モジュールに移動する
アプリの機能として ML Kit を使用するも、それが主要な機能ではない場合は、アプリをリファクタリングして、その機能と ML Kit の依存関係を動的機能モジュールに移動することを検討してください。
オンデマンド機能モジュールで ML Kit の機能が動作するようにするには、ベース APK の build.gradle
ファイルに ML Kit の Play ストア動的機能サポート ライブラリの依存関係を含めます。
dependencies {
// ...
implementation 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta2'
}
このようにすると、ユーザーはアプリの ML モデル(サイズが大きい場合がある)をダウンロードせずに済みます。
高度な設定: 未使用の ML Kit バイナリを除外する
ML Kit は、32 ビットと 64 ビットの両方のアーキテクチャをサポートするようにビルドされます。アプリが 32 ビットモードのみをサポートしている場合(32 ビットバイナリのみを提供するライブラリを使用している場合など)、ビルドから未使用の ML Kit ライブラリを除外できます。
android {
defaultConfig {
ndk {
// Don't package arm64-v8a or x86_64
abiFilters 'armeabi-v7a', 'x86'
}
}
}
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[null,null,["最終更新日 2025-09-04 UTC。"],[[["\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```"]]