ML Kit model installation paths on Android

All ML Kit features make use of Google-trained machine learning models (known as base models) by default. This guide is only applicable to base models. See here for guidance on custom models.

Models in ML Kit APIs can be installed in one of three ways:

  1. Unbundled: Models are downloaded and managed via Google Play Services.
  2. Bundled: Models are statically linked to your app at build time.
  3. Dynamically downloaded: Models are downloaded on demand.

Supported installation paths for each API

The table below shows which model installation paths are supported by each ML Kit feature:

Unbundled Bundled Dynamically downloaded
Text recognition v2
Face detection
Face mesh detection
Pose detection
Selfie segmentation
Barcode scanning
Image labeling
Object detection and tracking
Digital ink recognition
Document scanner
Subject segmentation
Google code scanner
Language identification
Translation
Smart Reply
Entity Extraction

API-specific guides show which installation options are available for the given API.

Key differences between installation options

Unbundled Bundled Dynamically downloaded
Where are models stored? Resides in Google Play Services and is not counted towards the storage used by this app Saved in app-specific storage after installation Saved in app-specific storage after model download
How does model size affect app size? Does not contribute to app size Directly contributes to app size Does not contribute to app size but increase the app-specific storage
When are models updated? Automatically updated when a newer version is released Need to update the app to update model Need to update the app to update model
When are models downloaded? Models must be downloaded before use All models and features are included when the app is installed, so are usable immediately Model downloads, updates, and deletions must be managed manually using the RemoteModelManager API
When are models removed from the device? Google Play Services will only remove the model from storage if all apps that depend on the model are uninstalled Models are removed from app-specific storage when the app is uninstalled Downloaded models are removed from app-specific storage when the app is uninstalled

How to choose between bundled and unbundled

If an API supports both the bundled and unbundled installation options:

  • Use the bundled option if you prioritize:

    • Complete feature functionality immediately after app installation
    • Feature functionality without network connection after app installation
  • Use the unbundled option if you prioritize:

    • Smaller app size
    • Automated model updates by Google Play Services

How to download models

When using the unbundled model option, you can specify how you want models to be downloaded to the device:

  • You can enable install-time model downloads by adding a declaration to your app's AndroidManifest.xml file. For example, the code snippet below shows how to configure your app to automatically download the Barcode Scanning model after your app is installed from the Play Store:

    <application ...>
          ...
          <meta-data
              android:name="com.google.mlkit.vision.DEPENDENCIES"
              android:value="barcode" >
          <!-- To use multiple models: android:value="barcode,model2,model3" -->
    </application>
    
  • You can request explicit download through Google Play Services ModuleInstallClient API.

  • If you don't enable install-time model downloads or request explicit download, the model will be downloaded the first time you run the feature. Until the download is completed, inference requests will fail.

How to update models

To update your models when using the bundled model or the dynamically downloaded models option:

  1. Update your app's gradle file to use the latest ML Kit feature client library.

    dependencies {
      implementation 'com.google.mlkit:barcode-scanning: 17.2.0' // The latest version number of the API
    }
    
  2. Rebuild your app.

Why some APIs offer dynamically downloaded models

Some ML Kit API have too many model options to bundle. For example, Digital ink recognition supports 300+ languages, and it’s not always necessary to put every language inside the feature during installation. For that purpose, we provide the third installation option, in which models are downloaded on demand after installation. Currently, only Digital ink recognition, Translation and Entity extraction have this option.