Reduce the size of your ML Kit Android app's APKs

Before you deploy to production an app that uses an ML Kit on-device model, consider following the advice on this page to reduce the download size of your app.

Build your app as an Android App Bundle

Build and deploy your app as an Android App Bundle so that Google Play can automatically generate APKs for specific screen densities, CPU architectures, and languages. Users will only have to download the APKs that match their device configuration, and most importantly, users only download the native code libraries that match their device architecture.

Advanced: Move optional ML features to dynamic feature modules

If you use ML Kit in a feature of your app that isn't its primary purpose, consider refactoring your app to move that feature and its ML Kit dependencies to a dynamic feature module.

In order for ML Kit features to work in an on-demand feature module, in your base apk's build.gradle file, include the ML Kit playstore dynamic feature support library dependency.

dependencies {
    // ...
    implementation 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta2'
}

By doing so, you prevent users from unnecessarily downloading your app's ML models, which can be large.

Advanced: Exclude unused ML Kit binaries

ML Kit is built with support for both 32-bit and 64-bit architectures. If your app only supports 32-bit mode—for example, because you use a library that only provides 32-bit binaries—you can exclude the unused ML Kit libraries from your build:

android {
  defaultConfig {
      ndk {
          // Don't package arm64-v8a or x86_64
          abiFilters 'armeabi-v7a', 'x86'
      }
  }
}