litert-runtime

Configures and implements LiteRT CompiledModel inference on Android in Kotlin.

9.3k|600|Updated Mar 16, 2026
Ready to run
npx skills add https://github.com/android/skills --skill litert-runtime-android
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: litert-runtime
Source: https://github.com/android/skills/tree/main/device-ai/litert/litert-runtime
Command: npx skills add https://github.com/android/skills --skill litert-runtime-android

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up on-device .tflite inference on Android requires careful thread management, buffer lifecycle handling, GPU fallback logic, and migration away from deprecated TFLite Interpreter APIs. ## Core Features & Use Cases - Gradle Configuration: Adds LiteRT 2.3.0 runtime and GPU accelerator dependencies with minSdk 24. - Inference Helper: Implements an AutoCloseable CompiledModel wrapper with TensorBuffer reuse, warm-up, and single-thread confinement. - GPU Fallback: Falls back to Accelerator.CPU when GPU compilation throws LiteRtException. - Migration: Replaces legacy org.tensorflow.lite.Interpreter and GpuDelegate code with the CompiledModel API. - Use Case: Build an Android image classifier that loads a .tflite model from assets, preprocesses Bitmap input, and runs inference on GPU with CPU fallback. ## Quick Start Use the litert-runtime skill to add LiteRT CompiledModel inference to my Android Kotlin app with GPU acceleration and CPU fallback.

Frequently Asked Questions about litert-runtime

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run a .tflite model on Android with LiteRT?▼

Use the LiteRT CompiledModel API with the litert and litert-gpu 2.3.0 dependencies in an Android Kotlin project. Create a single-thread executor to own the model, allocate TensorBuffer instances once, and run inference on the background thread.

What is the difference between LiteRT CompiledModel and the legacy TFLite Interpreter?▼

The legacy Interpreter API is deprecated and lacks the CompiledModel API's accelerator abstraction. LiteRT replaces GpuDelegate with CompiledModel.Options(Accelerator.GPU, Accelerator.CPU) and requires explicit buffer lifecycle management.

Does LiteRT support GPU acceleration on Android?▼

Yes, LiteRT supports GPU acceleration through the com.google.ai.edge.litert:litert-gpu artifact. The GPU option compiles the graph for the device GPU and falls back to CPU for unsupported operators.

Why does CompiledModel.create throw LiteRtException with Accelerator.GPU?▼

This exception occurs when the litert-gpu dependency is missing, the GPU cannot compile the model, or an operator is unsupported. Add the litert-gpu artifact and implement a CPU fallback in the catch block.

When should I not use LiteRT for on-device inference?▼

Do not use this skill for generative text LLMs with .litertlm files, Python model conversion, or apps already using LiteRT in Google Play services. Those scenarios require different runtimes or migration paths.

How do I migrate from org.tensorflow.lite.Interpreter to LiteRT?▼

Remove all org.tensorflow:tensorflow-lite artifacts and imports, add LiteRT 2.3.0 dependencies, replace GpuDelegate with CompiledModel.Options(Accelerator.GPU, Accelerator.CPU), and rewrite inference code using the CompiledModel helper pattern.