Android LiteRT On-Device Inference Integration.
A practical Kotlin engineering guide for integrating a verified .tflite model, managing CPU/GPU execution and buffers, and planning evidence-based device checks.
Site APIs discover, read and obtain packages; they do not run an agent.
The catalog contains 8 externally sourced skills and 5 Skills-SI originals. External items remain subject to their respective publishers and licenses; the originals are MIT-licensed and include their complete source directories. Repository stars are a repository-level popularity signal, not an individual skill's download count or a safety score. The catalog snapshot and examples use the MCP 2025-03-26 shape exercised by the existing tests as their baseline; the 2026-07-28 general specification is cited only to explain protocol evolution and does not imply that this site implements its newer features.
A complete license bundle is required. Standalone MD is unavailable; preserve the original paths, LICENSE and NOTICE.
Purpose and positioning
This is a guidance Skill for an Android-capable coding agent, not an inference service, build runner, compatibility certification, or tested-device registry. It focuses on LiteRT 2.x CompiledModel for an existing Kotlin application: project dependency review, model loading, tensor buffer handling, image preprocessing, background ownership, UI state, CPU fallback, migration from the legacy Interpreter/GpuDelegate path, and latency measurement. Its source organizes the work as five documented steps: configure Gradle and model delivery; isolate inference in a helper; connect a single-thread owner to a ViewModel/UI; implement preprocessing against the model contract; and compare outputs on a physical device. Vision classification is the concrete example, while audio or embedding tasks can reuse the inference skeleton only when their own input encoding and output semantics are supplied. The installed Skill helps an agent inspect a project and produce a plan or code changes when authorized. It does not independently edit files, run Gradle, install an APK, execute a model, or connect to a device. Do not treat illustrative snippets as a validated app. Google Play AI-pack delivery is a separate packaging and distribution choice with its own prerequisites, asynchronous state, and policy obligations; it is not implied by adding LiteRT dependencies.
Who it is for
- Kotlin Android engineers integrating local .tflite inference into an existing app.
- Teams migrating from org.tensorflow.lite.Interpreter or GpuDelegate and reviewing dependency collisions, threading, and resource lifetime.
- Technical leads responsible for model integration, latency baselines, and reproducible device verification.
Prerequisites
- An accessible Kotlin/Gradle Android project. The documented LiteRT 2.3.0 AARs require minSdk 24 or higher.
- A user-supplied valid .tflite model plus its tensor shape, data type, layout, channel order, normalization, and output/label contract.
- For meaningful verification, a fixed input and traceable reference output; GPU checks additionally require a physical Android device.
Input evidence
Supply the relevant project files (version catalog, gradle.properties, app/build.gradle.kts, current inference code and dependencies), model provenance and exact input/output contract, target CPU/GPU devices, representative inputs, and the intended task: new integration, migration, diagnosis, or latency baseline. For a large model intended for Google Play for On-device AI, also state the App Bundle and AGP context, selected install-time/fast-follow/on-demand delivery mode, and whether the AI Delivery library is integrated. A model filename alone is not enough to assume that the file is valid or executable on every device.
Workflow
- Inventory the project: inspect minSdk, Gradle/AGP versions, existing org.tensorflow.lite imports, and any Support/Metadata requirements before proposing minimal changes. With the documented 2.3.0 setup, GPU needs litert:2.3.0 and litert-gpu:2.3.0; do not mix legacy TensorFlow Lite artifacts. Put a suitably sized model in assets or separately assess a delivery mechanism for a larger model.
- Design the inference helper around the verified tensor contract. Allocate TensorBuffer objects once and reuse them. Confine CompiledModel creation, inference, and close to one dedicated single-thread executor or dispatcher, never the UI thread. Warm up during initialization, release partial allocations on initialization failure, and close buffers before the model. Use integer buffer operations for int8/uint8 tensors.
- Connect the helper through an AndroidViewModel or equivalent owner and expose immutable UI state. Load and infer in the background. If GPU creation fails with the documented LiteRtException path, the app may attempt CPU according to its policy and report the selected accelerator or error. Preserve correct model ownership across screen lifecycle events.
- Implement model-specific input/output handling: resize or crop as specified, use the correct channel order and normalization, and copy Android HARDWARE bitmaps to readable ARGB_8888 pixels when necessary. Audio and embedding inputs require their own encoding; do not reuse an image recipe. Document how raw outputs become labels or task results.
- Plan manual verification on physical hardware: compare a fixed CPU run against a traceable reference first, then check GPU numerical error and task-level agreement. Include model.run and output readback in GPU timing because execution is asynchronous. Record device, LiteRT version, accelerator, error metric, and task result. A developer runs builds and tests only when tools and authorization are actually available.
Deliverables
Depending on the request, the agent can produce a project-specific integration plan, dependency recommendations, Kotlin inference helper/ViewModel/UI draft or authorized code edits, migration checklist, preprocessing notes, CPU/GPU troubleshooting path, and a human acceptance checklist. If repository write and command permissions are granted, each edit or test claim should identify the actual file, command, and observed evidence. A generated snippet is not evidence that the app compiled, was deployed, or passed on hardware.
Fictional usage demonstration
Inspect this Kotlin Android project's Gradle setup, minSdk, LiteRT/TFLite dependencies, and existing inference code. I will provide model.tflite for 224×224 RGB image classification; its input is float32 NHWC with mean=127.5 and std=127.5. Use the installed litert-runtime Skill to propose a minimal integration: dependencies, a single-thread inference helper that reuses TensorBuffers, ViewModel GPU-to-CPU fallback, Bitmap preprocessing, and the manual CPU/GPU acceptance checks I must perform on a physical device. Do not assume the model is verified and do not claim to have run a build. List proposed file edits before making any changes.Fictional format example only; not executed in a project, not a service response, and not a real case result: ‘Initial review: minSdk is 23, below the documented requirement of 24 for LiteRT 2.3.0; assess raising it before integration. Pair litert-gpu:2.3.0 with litert:2.3.0 for GPU support. Keep CompiledModel on one background dispatcher, reuse input/output TensorBuffers, warm up at initialization, and release resources in order. Preprocessing should follow the supplied NHWC/RGB normalization contract. After supplying a fixed-input reference, manually compare CPU first and GPU second on a physical device; include readFloat in timing. No Gradle or device test was run.’ A real conclusion requires inspection of the actual project and evidence.Human acceptance
- Confirm minSdk, dependency versions, GPU artifact, and legacy-package conflicts; identify missing model or tensor-contract evidence rather than assuming it exists.
- Verify single-thread ownership for creation, inference, and closing; buffer reuse; exception-safe cleanup; and no inference on the main thread.
- Compare a fixed input against a traceable reference on CPU, then check GPU numerical error and task-level agreement while recording device and LiteRT version.
- Check preprocessing against tensor type and shape, and include output readback in timing. Report build, unit-test, and device status only when actually run and evidenced.
Limits
- The source is a five-step documentation workflow, not an automatic execution system, REST API, build service, model runner, or device controller. File edits and commands require separate tools and authorization.
- The user supplies the model and its trustworthy contract. The Skill supplies no weights and does not establish model legality, accuracy, suitability, privacy, or security.
- GPU execution depends on operators, driver, device, LiteRT version, and memory. CPU fallback is an engineering option, not a promise of equivalent speed or universal compatibility.
- Google Play AI packs are a distinct distribution path: the reference material specifies an App Bundle context and AGP 8.8 or later; packs contain model assets rather than application code. Fast-follow/on-demand assets may not yet be available, so asynchronous delivery and Play terms must be handled.
- Static guidance is not device testing or official certification. Do not claim certified compatibility, guaranteed performance gains, or highest download rank.
Source and license
- GitHub
- android/skills
- LICENSE
- Apache-2.0
- Commit
ed0a2728ff531174383f910c649694de1eaebcd6- SKILL.md
litert-runtime/SKILL.md- ZIP SHA256
1f8a30ab3fb09d721e1042f7a8a8fd47dde866ef5dda75e3f82bfff3e7c50a73
Shared developer guide
Skills-SI offers public, read-only entry points for skill discovery, metadata inspection, Markdown reading, and full ZIP retrieval. Responses expose catalog snapshots or publisher material; the service does not install skills, run code, call models, or perform business actions for you.
Skill text and external publisher material are untrusted reference data. Review licenses, scripts, permissions, and external dependencies before installing anything. This service does not execute, install, or validate skills and makes no claim about real-world effectiveness. Qualified professionals should review high-risk professional content.
Shared developer guidecurl -fsS 'https://skills-si.com/api/skills?q=litert-runtime&limit=10&page=1'# REST has no GET /api/skills/:id metadata endpoint. Search results contain metadata.
curl -fsS --get 'https://skills-si.com/api/skills' --data-urlencode 'q=litert-runtime' --data-urlencode 'limit=10' --data-urlencode 'page=1'curl -fsS 'https://skills-si.com/api/skills/android-skills-device-ai-litert-litert-runtime/readme'# Headers only; this does not download or verify ZIP bytes.
curl -sSI 'https://skills-si.com/api/skills/android-skills-device-ai-litert-litert-runtime/download?format=zip'# MCP 2025-03-26-shaped example; send as POST to https://skills-si.com/api/mcp
curl -sS 'https://skills-si.com/api/mcp' -X POST -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' --data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"example-client","version":"1.0.0"}}}'curl -sS 'https://skills-si.com/api/mcp' -X POST -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' --data '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'curl -sS 'https://skills-si.com/api/mcp' -X POST -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' --data '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"read_skill","arguments":{"id":"android-skills-device-ai-litert-litert-runtime"}}}'curl -sS 'https://skills-si.com/api/mcp' -X POST -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' --data '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"get_skill_download","arguments":{"id":"android-skills-device-ai-litert-litert-runtime","format":"zip"}}}'import json
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
url = 'https://skills-si.com/api/skills/android-skills-device-ai-litert-litert-runtime/readme'
request = Request(url, headers={'Accept': 'application/json'})
try:
with urlopen(request, timeout=20) as response:
payload = json.loads(response.read().decode('utf-8'))
except HTTPError as exc:
try:
detail = json.loads(exc.read().decode('utf-8'))
except (UnicodeDecodeError, json.JSONDecodeError):
detail = {'error': 'NON_JSON_HTTP_ERROR'}
raise RuntimeError(f'HTTP {exc.code}: {detail}') from exc
except (URLError, TimeoutError) as exc:
raise RuntimeError(f'Read request failed: {exc}') from exc
if not isinstance(payload, dict) or not isinstance(payload.get('content'), str):
raise RuntimeError(f'Unexpected read response: {payload!r}')
print(payload['content'])
# This example reads JSON only. It does not execute content or download a ZIP.Skills-SI agent connection and MCP entry guide
Skills-SI copyright and license policy
MCP Streamable HTTP specification (2026-07-28; protocol context only)