Setup guide for Android

This page shows you how to set up your development environment to use MediaPipe Tasks in your Android applications with Kotlin or Java.

Supported devices and platforms

To create Android applications with MediaPipe Tasks, your development environment requires the following:

  • Android Studio (Hedgehog or newer recommended), or another compatible Gradle IDE.
  • Android SDK version 24 or higher (minSdk = 24).
  • Android device with at least the minimum SDK version. An Android emulator works for tasks that don't require a physical camera or GPU delegate.

Developer environment setup

Before running a MediaPipe task in an Android application, create a new Android Studio project or open an existing app. MediaPipe fits naturally into the Data layer of your app, which encapsulates model execution and business logic. For more information on Android app architecture, refer to Guide to app architecture.

Android device setup

Enable Developer options and USB debugging on a physical Android device before using it to test your application. For instructions, refer to Configure on-device developer options.

For tasks that don't require a live camera or microphone, you can also test in an Android Emulator. See Run apps on the Android Emulator.

Example code setup

The MediaPipe Samples repository contains runnable Android projects for MediaPipe Tasks.

To import and build an example project:

  1. Start Android Studio.
  2. Select File > New > Import Project.
  3. Navigate to the example directory containing build.gradle or build.gradle.kts, for example: .../mediapipe-samples/examples/hand_landmarker/android
  4. Accept Gradle Sync if prompted.
  5. Connect an Android device with USB debugging enabled (or select an emulator) and click Run.

MediaPipe Tasks dependencies

MediaPipe Tasks provides five prebuilt Maven libraries for vision, text, audio, retrieval, and decision tasks. Place .task, .tflite, or .litertlm model files in your module's src/main/assets/ directory (or load them from device storage), and add the required domain artifact in Gradle:

Vision tasks

The vision library (tasks-vision) handles images, decoded video frames, and live CameraX streams. See Prepare vision input data to wrap bitmaps and camera frames in MPImage.

Android (Kotlin)

dependencies {
  implementation("com.google.mediapipe:tasks-vision:latest.release")
}

Android (Java)

dependencies {
  implementation 'com.google.mediapipe:tasks-vision:latest.release'
}

Text tasks

The text library (tasks-text) handles classification, language detection, embeddings, proofreading, and summarization.

Android (Kotlin)

dependencies {
  implementation("com.google.mediapipe:tasks-text:latest.release")
}

Android (Java)

dependencies {
  implementation 'com.google.mediapipe:tasks-text:latest.release'
}

Audio tasks

The audio library (tasks-audio) handles sound event classification, speech transcription, and neural text-to-speech synthesis. See Prepare audio input data to format AudioData and AudioRecord buffers.

Android (Kotlin)

dependencies {
  implementation("com.google.mediapipe:tasks-audio:latest.release")
}

Android (Java)

dependencies {
  implementation 'com.google.mediapipe:tasks-audio:latest.release'
}

Retrieval tasks

The retrieval library (tasks-retrieval) provides on-device document chunking, vector search for RAG (SemanticRetriever), and multimodal text, image, and audio embeddings (UniversalEmbedder).

Android (Kotlin)

dependencies {
  implementation("com.google.mediapipe:tasks-retrieval:latest.release")
}

Android (Java)

dependencies {
  implementation 'com.google.mediapipe:tasks-retrieval:latest.release'
}

Decision tasks

The decision library (tasks-decision) evaluates structured choices, boolean conditions, and rubric scores (DecisionMaker).

Android (Kotlin)

dependencies {
  implementation("com.google.mediapipe:tasks-decision:latest.release")
}

Android (Java)

dependencies {
  implementation 'com.google.mediapipe:tasks-decision:latest.release'
}

BaseOptions configuration

BaseOptions configures the model asset and hardware delegate for MediaPipe Task APIs:

Option name Description Accepted values
modelAssetBuffer The model asset file contents as a direct ByteBuffer or MappedByteBuffer. ByteBuffer | MappedByteBuffer
modelAssetPath The relative path to a model asset file in the Android module's assets folder. String
modelAssetFileDescriptor The native file descriptor integer of a model asset file. Integer
delegate Enables hardware acceleration through a device delegate to run the MediaPipe pipeline. Default value: Delegate.CPU. Delegate.CPU | Delegate.GPU

Hardware acceleration

MediaPipe Tasks supports GPU-accelerated execution on Android devices using Delegate.GPU in BaseOptions:

Android (Kotlin)

import com.google.mediapipe.tasks.core.BaseOptions
import com.google.mediapipe.tasks.core.Delegate

val baseOptions = BaseOptions.builder()
    .setDelegate(Delegate.GPU)
    .setModelAssetPath("model.task")
    .build()

Android (Java)

import com.google.mediapipe.tasks.core.BaseOptions;
import com.google.mediapipe.tasks.core.Delegate;

BaseOptions baseOptions = BaseOptions.builder()
    .setDelegate(Delegate.GPU)
    .setModelAssetPath("model.task")
    .build();

Troubleshooting

For help with technical questions related to MediaPipe, visit the discussion group or Stack Overflow for support from the community. To report bugs or make feature requests, file an issue on GitHub.

For help setting up your Android development environment, visit the Android developer documentation.