Page Summary
-
Some Google Play services SDK functionalities are provided as on-demand modules to conserve device storage and memory.
-
While Google Play services usually handles module installation automatically, the
ModuleInstallClientAPI allows for more control over this process. -
ModuleInstallClientenables checking module availability, requesting installations (deferred or urgent), monitoring progress, and handling errors. -
You can simulate module install API results for testing purposes using the
FakeModuleInstallClientin conjunction with a dependency injection framework like Hilt.
As described in the Overview of Google Play services article, SDKs powered by Google Play services are backed by on-device services on Google-certified Android devices. To conserve storage and memory across the entire fleet of devices, some services are provided as modules that are installed on-demand when your app requires the relevant functionality. For example, ML Kit provides this option when using models in Google Play services.
In most cases, the Google Play services SDK downloads and installs the necessary modules automatically when your app uses an API that requires them. However, you might want to have more control over the process, such as when you want to improve the user experience by installing the module in advance.
The ModuleInstallClient API gives you the ability to:
- Check if the modules are already installed on the device.
- Request to install the modules.
- Monitor the installation progress.
- Handle errors during the installation process.
This guide shows you how to use ModuleInstallClient to manage modules in your
app. Note that the following code snippets use the
TensorFlow Lite SDK
(play-services-tflite-java) as an example, but these steps are applicable for
any library that's integrated with OptionalModuleApi.
Before you begin
To prepare your app, complete the steps in the following sections.
App prerequisites
Make sure that your app's build file uses the following values:
- A
minSdkVersionof23or higher
Configure your app
In your top-level
settings.gradlefile, include Google's Maven repository and the Maven central repository within thedependencyResolutionManagementblock:dependencyResolutionManagement { repositories { google() mavenCentral() } }In your module's Gradle build file (usually
app/build.gradle), add the Google Play services dependencies forplay-services-baseandplay-services-tflite-java:dependencies