On-Device LLM Inference on Android With MediaPipe and Gemma

Run a language model entirely on an Android phone with no server and no network call. MediaPipe is now maintenance-only, so this tutorial covers LiteRT-LM too.

By Galactic News Editorial · Published 2026-11-24T07:55:07+00:00 · Updated 2026-11-24T07:55:07+00:00

On-device LLM Android MediaPipe Gemma running offline on a phone

On-Device LLM Inference on Android With MediaPipe and Gemma

You can run a language model entirely on an Android phone. No server. No network call. No user data leaving the device. On-device LLM Android MediaPipe Gemma is the classic way to do it, but the landscape shifted in 2026. The MediaPipe LLM Inference API is now in maintenance-only mode. Google recommends new Android projects use the LiteRT-LM Android (Kotlin) API instead.

This tutorial covers both paths. It shows the MediaPipe setup, then explains the LiteRT-LM migration. By the end, you will know how to ship offline text generation in an Android app.

Why Run an LLM On-Device

On-device inference solves three problems at once. Privacy is the first. Prompts and responses never leave the phone, which matters for health, finance, and personal data. Latency is the second. There is no round trip to a server. Offline use is the third. The feature keeps working on a plane, in a tunnel, or on a weak connection.

The trade-off is capability. A phone-sized model cannot match a data-centre model. Gemma 3 1B, the usual starting point, handles summarising, rewriting, simple question answering, and structured extraction well. It is not the right tool for deep reasoning or long-form research.

On-Device LLM Android MediaPipe Gemma: What Changed

Google's official guide now carries a clear warning. The MediaPipe LLM Inference API is in maintenance-only mode. New Android projects should migrate to LiteRT-LM, described by Google as the production-ready orchestration layer for running LLMs with LiteRT. LiteRT-LM offers Kotlin, Swift, JavaScript, Python, Flutter, and C++ APIs, plus hardware acceleration.

MediaPipe still works for existing projects. The concepts transfer directly. Model files, token limits, and prompt design behave the same way in both APIs. If you are starting fresh, build on LiteRT-LM. If you maintain a MediaPipe app, plan the migration now rather than later.

What You Need Before You Start

Build It Step by Step

These steps follow Google's official MediaPipe quickstart. The LiteRT-LM path uses the same shape with a different package.

  1. Add the dependency. In your app module's build.gradle, add the MediaPipe generative AI tasks library. The current version in Google's guide is com.google.mediapipe:tasks-genai:0.10.27. Use the version your project targets.
  2. Download the model. Get Gemma 3 1B in 4-bit quantised format from Hugging Face. Keep the .task file somewhere your build can reach it.
  3. Push the model to the device. Clear any old model, create the folder, and push the file with ADB:
    adb shell rm -r /data/local/tmp/llm/
    adb shell mkdir -p /data/local/tmp/llm/
    adb push <output_path> /data/local/tmp/llm/<model_version>.task
  4. Initialise the task. Build LlmInferenceOptions with the model path, then create the task:
    val taskOptions = LlmInferenceOptions.builder().setModelPath("/data/local/tmp/llm/gemma-3-1b-it-int4.task").build()
    val llmInference = LlmInference.createFromOptions(context, taskOptions)
  5. Generate a response. Call generateResponse() with a prompt string. The call returns a single generated response:
    val result = llmInference.generateResponse(inputPrompt)
  6. Try the sample app. Google's AI Edge Gallery is an open-source Android app that demonstrates on-device generative AI capabilities, including LLM inference. Use it to explore configuration options before you commit to your own UI.
  7. Plan the LiteRT-LM migration. For new projects, start with the LiteRT-LM Android guide instead. It offers the same on-device execution with active development, NPU and GPU acceleration, and a file builder for converting models.

Configuration Options Worth Setting

Two settings matter most in early testing.

OptionWhat it doesGuidance
modelPathWhere the model file lives inside the project or on the devicePoint it at the exact .task file you pushed
maxTokensThe maximum number of tokens the model may generateKeep it small for short answers, larger for summaries

Test on the weakest device you plan to support. Token speed and memory use vary sharply between phone models. A prompt that feels instant on a flagship can crawl on a mid-range device.

Limits to Plan Around

On-device LLMs have hard limits. Plan for them early.

First, model size. A 1B model in 4-bit quantisation is small enough for a phone. Larger models need more memory and more time. Bigger is not always better on a device with limited RAM.

Second, device support. The API targets high-end devices. Older phones may run slowly or not at all. Test your minimum supported device before you promise the feature.

Third, the maintenance warning. MediaPipe LLM Inference receives maintenance only. New features, model support, and performance work now land in LiteRT-LM. Building a new product on a maintenance-mode API is a risk you should take only with a migration plan.

Bottom Line

On-device LLM Android MediaPipe Gemma remains a working path for offline text generation on Android. The MediaPipe API runs Gemma 3 1B on-device with a few lines of Kotlin. But Google's direction is clear. New projects should use LiteRT-LM. Start there, test on real hardware, and keep prompts short. Offline AI on a phone is no longer a demo. It is a shipping feature.