You must do these before deploying your ML Kit Android App to production

ML Kit Android App for production

Hi Folks! if you have learnt how to implement Machine Learning in your Android App,( if not, you may refer ML Kit Tutorial Series), it's time to consider deployment and production. In the ML Kit Tutorials, we learnt about on-device ML models and Cloud-based ML models. In the case of Cloud-based models, the ML Engine stays in the cloud and the job of processing and learning happens in the Cloud. But in the case of On-device models, your device downloads the model first. As a consequence, when there are situations like large number of users don't need ML features then the extra space consumed by the ML model could be overkill. Lets take a look at how we can address some of these issues:

Build your app as an Android App Bundle

If you are using latest Android Studio, then consider building your app as an Android App Bundle. Using App Bundle, Google Play can automatically generate APKs for specific screen densities, CPU architectures, and languages. Your users will have to download only the APKs that match their device configuration. Here users download only the native code libraries that match their device architecture.

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. Refer this post to learn how to do this. In this way, you save you users from downloading large ML models that may never be required by them.

Exclude unused ML Kit binaries

ML Kit supports both 32-bit and 64-bit architectures. If your app supports only 32 architectures, you can exclude the unused ML Kit libraries from your build as follows:

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

Keep your Cloud Credentials safe

If your Android app uses one of ML Kit's cloud APIs, it is important that you take some additional steps to prevent unauthorized API access before you launch your app in production. For Testing and development, you are better off creating a debug-only API key. Refer this post for details on how you can portect your Cloud credentials.


Ratul Doley
Ratul Doley
Entrepreneur and AI researcher. Currently learning and working on Unsupervised learning and Data Clustering. Professional Android app developer and designer. Updated Nov 15, 2018