litert-runtime
Configures and implements LiteRT (.tflite) on-device inference on Android
Install / Use
npx skills add android/skills --skill litert-runtimeInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
AI & Machine LearningSupported Platforms
Our assessment of litert-runtime
litert-runtime scores 93/100 on our quality scale, 240th of 947 AI & Machine Learning skills we index (top 26%).
Its SKILL.md is 26 KB long, well organised into 11 sections with 6 code examples: a thorough specification that gives an agent plenty to work with.
With 7,514 GitHub stars, it is one of the more widely adopted skills in the catalogue.
Maintenance, license and trust
- The repository was last updated about 2 months ago, so litert-runtime is actively maintained.
- It is released under the Apache-2.0 license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
Safety scan
No issues foundOur scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful.
AI review by kimi-k2.7-code on 2026-11-16. Automated pattern scan on 2026-11-15. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.
litert-runtime compared with similar skills
All 4 of these similar skills score higher than litert-runtime; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| litert-runtime (this skill)by android | 93 | 7.5k | 54d ago | SKILL.md |
| claude-memby thedotmack | 100 | 117.6k | today | CLAUDE.md |
| taste-skillby Leonxlnx | 100 | 116.8k | 8d ago | CLAUDE.md |
| Agent-Reachby Panniantong | 100 | 112.3k | 8d ago | CLAUDE.md |
| Understand-Anythingby Egonex-AI | 100 | 92.8k | 1d ago | CLAUDE.md |
Frequently asked questions
- How do I install litert-runtime?
- Run
npx skills add android/skills --skill litert-runtime. The install tabs above show the steps for each supported agent. - Which AI agents does litert-runtime work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is litert-runtime safe to use?
- Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful. It is Apache-2.0-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is litert-runtime still maintained?
- The repository was last updated about 2 months ago, so litert-runtime is actively maintained.
Skill content
View source on GitHubname: litert-runtime description: Configures and implements LiteRT (.tflite) on-device inference on Android in Kotlin using the CompiledModel API on CPU and GPU. Use this skill for any Android LiteRT or .tflite task, including Gradle setup, image classification or vision/audio/embedding helpers, TensorBuffer reuse, CPU memory optimization, Bitmap preprocessing, AndroidViewModel GPU-to-CPU fallback with warm-up on a single-thread dispatcher, LiteRT in Google Play services (play-services-litert), migrating from legacy org.tensorflow.lite.Interpreter, GpuDelegate, or play-services-tflite, and latency benchmarking. Don't use for running generative text LLMs with .litertlm files or for Python model conversion. license: Complete terms in LICENSE.txt metadata: author: Google LLC last-updated: '2026-11-10' keywords:
- LiteRT
- CompiledModel
- tflite
- Android app
- GPU
- TensorBuffer
This skill provides step-by-step guidance for building an Android app that runs
a .tflite model with the LiteRT CompiledModel API
(com.google.ai.edge.litert:litert 2.x; source repository) on the CPU or
the GPU, with the runtime bundled in the APK or from Google Play services. Don't
use the deprecated org.tensorflow.lite.Interpreter API. For
open text language models using .litertlm files, suggest the litert-lm
skill.
Prerequisites
- A Kotlin Android project (
minSdkmust be24or higher, as declared by the LiteRT 2.3.0 AARs). - The runtime that Step 1 picks: the Google Play services runtime (
com.google.android.gms:play-services-litert, the default; see LiteRT in Google Play services), or the bundled runtime (implementation("com.google.ai.edge.litert:litert:2.3.0")andimplementation("com.google.ai.edge.litert:litert-gpu:2.3.0")from Google Maven). For the bundled runtime, from 2.3.0 the GPU accelerator is the second artifact: withlitertalone the app builds, andCompiledModel.createwithCompiledModel.Options(Accelerator.GPU)throwsLiteRtExceptionbecause the APK has no GPU accelerator library. WithCompiledModel.Options(Accelerator.GPU, Accelerator.CPU)it doesn't throw: the model runs on the CPU while the app reports the GPU, and only Logcat shows it (GPU accelerator could not be loaded and registered). No manifest entry is needed:litert-api, whichlitertdepends on, declares the OpenCL driver libraries (uses-native-library) in its own manifest. - A verified
.tflitemodel and its input contract (input dimensions, mean, standard deviation, channel order, and tensor layout). For models with a verified recipe, inspect the LiteRT model recipes.
Critical mandates
- Single-thread confinement : One single-thread executor or confined coroutine dispatcher must own the
CompiledModelinstance. Creation, inference, and closing must execute on that same background thread, never on the main thread. - Buffer lifecycle : Allocate
TensorBufferinstances once usingcreateInputBuffersandcreateOutputBuffers, reuse them across inferences, and close all input and output buffers before closing theCompiledModel. - Synchronous timing :
model.runenqueues work on the GPU and returns before GPU execution completes. Always measuremodel.runand output buffer readback (outputs[0].readFloat) together. - Warm-up and exception safety : Execute one warm-up inference inside the helper constructor's
initblock so first-run GPU shader compilation doesn't block the first user interaction, and callcloseincatchbefore rethrowing so neitherCompiledModelnorTensorBufferhandles leak if buffer allocation or warm-up throws. - Runtime choice : Before Step 1, you must read LiteRT in Google Play services and choose the runtime. Use the Google Play services runtime unless the app needs the NPU, custom operators, or a Support library class that this skill can't replace (such as
MetadataExtractor), or also targets devices without Google Play services. Never put both runtimes in the same build variant. - Migration : When the app already uses
org.tensorflow.litecode, you must read the "Migrating from legacy TFLite Interpreter" section in full before you edit any file. Migrated code must not import anyorg.tensorflow.liteclass (includingDataType), every legacy GPU choice (GpuDelegate, or the Support library'sModel.Device.GPU) becomesCompiledModel.Options(Accelerator.GPU, Accelerator.CPU), and an NNAPI choice maps to that same GPU option.
Detailed steps
Step 1: Configure Gradle and place the model file
Search the project for libs.versions.toml, gradle.properties,
app/build.gradle.kts, and any existing org.tensorflow.lite imports before
editing build files. Then pick the runtime:
- Google Play services runtime (default) : Use it unless one of the bundled runtime cases applies, also when the request doesn't name a runtime. You must read LiteRT in Google Play services now: its dependencies replace the ones in this step, and its
Environmentreplaces theenvironmentproperty of Step 2. Use version17.0.0exactly, and run./gradlew assembleDebug(not--dry-run) after you add it. Switch to the bundled runtime only when that build reportsCould not find com.google.android.gms:play-services-litert:17.0.0, and tell the user, also when the user asked for Google Play services. Never leave the build broken. - Bundled runtime : Use it only when the app needs the NPU, custom operators, or a Support library class that this skill can't replace (such as
MetadataExtractor), when the app also targets devices without Google Play services, or when the user asks for it.FileUtil,ImageProcessor,TensorImage, andTensorLabeldon't count: replace them as LiteRT in Google Play services describes. For the bundled runtime, configureminSdkand add the LiteRT runtime and GPU accelerator dependencies inapp/build.gradle.kts:
android {
defaultConfig {
minSdk = 24
}
}
dependencies {
implementation("com.google.ai.edge.litert:litert:2.3.0")
implementation("com.google.ai.edge.litert:litert-gpu:2.3.0")
}
Place bundled models at app/src/main/assets/model.tflite (AGP stores .tflite
files uncompressed by default). Deliver a model that exceeds the base APK size
limit through Play for On-Device AI as an AI pack, or download it into
context.filesDir (bundletool --local-testing installs AI packs locally
without Google Play). Read an install-time AI pack through AssetManager. Load
a fast-follow or on-demand AI pack or a downloaded file from its on-disk
filePath using CompiledModel.create(filePath, CompiledModel.Options(accelerator), environment) in place of the asset call in
Step 2. Obtain the pack's directory from the AI Delivery library
(com.google.android.play:ai-delivery) using
AiPackManagerFactory.getInstance(context).getPackLocation(name)?.assetsPath(),
which returns null until the pack has finished downloading.
With 2.3.0, nothing is added to gradle.properties: litert 2.3.0 declares
the namespace com.google.ai.edge.litert.impl and its dependency litert-api
2.3.0 declares com.google.ai.edge.litert, so AGP 9.x builds the project. With
2.2.0 or 2.1.6, both libraries declare com.google.ai.edge.litert, and AGP
9.x stops at processDebugMainManifest (AGP 8.x reports it as a warning and
builds); for those two versions, add android.uniquePackageNames=false to
gradle.properties, and remove it when moving to 2.3.0 because it also hides
the same clash between any other two libraries. Excluding litert-api instead
doesn't work: CompiledModel and Accelerator are in litert-api, and the
build then fails at compileDebugKotlin.
Step 2: Implement the inference helper class
Isolate CompiledModel and its TensorBuffer instances in a dedicated
AutoCloseable helper class free of Android UI types:
import android.content.Context
import com.google.ai.edge.litert.Accelerator
import com.google.ai.edge.litert.CompiledModel
import com.google.ai.edge.litert.Environment
import com.google.ai.edge.litert.TensorBuffer
const val INPUT_SIZE = 224 * 224 * 3
private val environment by lazy { Environment.create() }
class Classifier(context: Context, accelerator: Accelerator) : AutoCloseable {
private val model = CompiledModel.create(
context.assets,
"model.tflite",
CompiledModel.Options(accelerator),
environment
)
private val inputs = mutableListOf<TensorBuffer>()
private val outputs = mutableListOf<TensorBuffer>()
init {
try {
inputs += model.createInputBuffers()
outputs += model.createOutputBuffers()
infer(FloatArray(INPUT_SIZE))
} catch (e: Exception) {
close()
throw e
}
}
fun infer(input: FloatArray): FloatArray {
inputs[0].writeFloat(input)
model.run(inputs, outputs)
return outputs[0].readFloat()
}
override fun close() {
(inputs + outputs).forEach { it.close() }
model.close()
}
}
Accelerator.CPU requires nothing from the device. Accelerator.GPU compiles
the graph for the GPU; when the GPU can't execute the model, the constructor
throws LiteRtException (from create for an operator the GPU doesn't support,
and on the Android emulator from create or from buffer allocation). A missing
asset or a file that isn't a valid model also throws LiteRtException from
create.
The buffers are created once with the model, reused for every inference, and
closed before the model. One Environment serves every model in the process and
stays open, so LiteRT loads the GPU accelerator library once rather than on
every create call. The constructor ends with one warm-up inference (the first
GPU run includes shader compilation) and closes the model and its buffers if any
step in init throws. INPUT_SIZE is the model's input element count:
writeFloat throws on a longer array and writes a shorter one without an error,
so a wrong size produces an incorrect result. For int8 or uint8 tensors, use
writeInt8 and readInt8 on TensorBuffer instead of writeFloat and
readFloat.
When memory matters, use the following options:
- Load from a path :
create(context.assets, ...)keeps a copy of the asset's bytes in the native heap while the model is open. Copy the asset once intocontext.noBackupFilesDir(a downloaded or AI pack file is already on disk) and callcreate(filePath, ...)so the file is mapped and reclaimable. Version the staged filename, bump the version when the bundled model changes, and delete the previous version's file. Copy to a temporary file and rename it so a copy interrupted by process death is never loaded:
import android.content.Context
import com.google.ai.edge.litert.Accelerator
import com.google.ai.edge.litert.CompiledModel
import java.io.File
fun stageModelAsset(
context: Context, assetName: String = "model.tflite", version: String = "v1"
): File =
File(context.noBackupFilesDir, "$version-$assetName").also { file ->
if (!file.isFile) {
context.noBackupFilesDir.listFiles()?.forEach {
if (it.name.endsWith("-$assetName")) it.delete()
}
val tmp = File("${file.path}.tmp")
context.assets.open(assetName).use { input ->
tmp.outputStream().use { output -> input.copyTo(output) }
}
check(tmp.renameTo(file))
}
}
fun memoryOptions(
context: Context,
accelerator:
Truncated for display — read the full file on GitHub.
Related Skills
claude-mem
117.6kPersistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
taste-skill
116.8kAgent skills that give coding agents taste: art direction, reference images and a browser check instead of generic AI pages
Agent-Reach
112.3kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Understand-Anything
92.8kGraphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
