At I/O 2018, Google announced the release of Firebase’s ML Kit, a developer-friendly software package that allows mobile engineers to quickly integrate Machine Learning features in their applications with just a few lines of code. With ML Kit, we’re able to do amazing things like face detection, text recognition, and landmark recognition, all without needing to have deep knowledge about neural networks or model optimization.

In this article, I’m going to show you how to make a working Snapchat Filter Android application in 7 steps. You can find the example code in this GitHub repo — all PRs are welcomed.

(The resulting app puts sunglasses over your eyes and dangles a cigarette from your lips).

The development environment used in this tutorial is as follows:

Android Studio 3.1.3

Kotlin 1.2.41

MacBook Pro Mid 2015 running macOS High Sierra 10.13.5

Step 1: Prepare the workspace and dependencies

Fire up Android Studio and create a new Android application, tick the Include Kotlin support option in the wizard, and name the project firebase_ml_snapchat_filter . Finally, click Finish to complete the project creation process.

Open the build.gradle file at the root folder, and add the following dependency in the buildscript block:

classpath ‘com.google.gms:google-services:4.0.0’

There is implicit dependency between Firebase and Google services, so we need to use the Google service plugin in our project as well.

Open the app/build.gradle file , and add the following dependencies:

The first two are the Firebase core and ML Kit dependencies. The lifecycle extension is added to handle the activity lifecycle events, and the com.otaliastudios:cameraview library provides a high-level interface that makes the Android camera programming a lot easier. You can, of course, use the official Android camera APIs. IMHO those APIs are for the brave developers.

Now that we have the dependencies in place, we add the following line at the end of the build.gradle file to apply the Google service plugin.

apply plugin: ‘com.google.gms.google-services’

Step 2: Create a Firebase Android app

Open your favorite web browser and navigate to the Firebase console. Click on the Add Project button and give the project a name of your choice if you haven’t yet created one. Alternatively you can create a new Android App on top of an existing Firebase project.