<br />

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](https://developer.android.com/studio/index.html) (Hedgehog or newer recommended), or another compatible Gradle IDE.
- Android SDK version 28 or higher (`minSdk = 28`).
- 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](https://developer.android.com/topic/architecture/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](https://developer.android.com/topic/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](https://developer.android.com/studio/debug/dev-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](https://developer.android.com/studio/run/emulator).

## Example code setup

The [MediaPipe
Samples](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples)
repository contains runnable Android projects for MediaPipe Tasks.

To import and build an example project:

1. Start [Android Studio](https://developer.android.com/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](https://developers.google.com/edge/mediapipe/solutions/prepare_data.md.txt#vision) to
wrap bitmaps and camera frames in `MPImage`.

### Android (Kotlin)

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

### Android (Java)

```groovy
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)

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

### Android (Java)

```groovy
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](https://developers.google.com/edge/mediapipe/solutions/prepare_data.md.txt#audio) to
format `AudioData` and `AudioRecord` buffers.

### Android (Kotlin)

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

### Android (Java)

```groovy
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)

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

### Android (Java)

```groovy
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)

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

### Android (Java)

```groovy
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)

```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)

```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](https://groups.google.com/forum/#!forum/mediapipe) or [Stack
Overflow](https://stackoverflow.com/questions/tagged/mediapipe) for support from
the community. To report bugs or make feature requests, [file an issue on
GitHub](https://github.com/google-ai-edge/mediapipe/issues).

For help setting up your Android development environment, visit the [Android
developer documentation](https://developer.android.com/guide).