본문으로 건너뛰기
Skillpedia
모바일 앱10k · #11912

litert-runtime

하는 일

이 스킬은 LiteRT CompiledModel API를 사용해 .tflite 모델로 Android 앱에 기기 내 머신러닝을 추가하는 방법을 안내합니다. 휴대폰에서 이미지, 오디오 또는 임베딩 작업을 하는 Android 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓Android 앱 안에서 이미지 분류나 다른 비전 모델을 실행하고 싶을 때.
  • ✓Play services 런타임과 번들 런타임 중에서 고르며 LiteRT를 Gradle에 설정해야 할 때.
  • ✓GPU에서 .tflite 모델을 실행하되 문제가 생기면 CPU로 전환하고 싶을 때.

스킬 링크

https://github.com/android/skills/blob/main/device-ai/litert/litert-runtime/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/android/skills/blob/main/device-ai/litert/litert-runtime/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“LiteRT를 사용해 GPU에서 .tflite 모델로 이미지 분류 기능을 내 Android 앱에 추가해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 런타임을 고르고, Gradle 의존성을 추가하고, 모델에 맞게 이미지를 준비하는 과정을 돕습니다. 그다음 필요할 때 GPU에서 모델을 실행하고 CPU로 대체하는 방법을 보여 줍니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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 (minSdk must be 24 or 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") and implementation("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: with litert alone the app builds, and CompiledModel.create with CompiledModel.Options(Accelerator.GPU) throws LiteRtException because the APK has no GPU accelerator library. With CompiledModel.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, which litert depends on, declares the OpenCL driver libraries (uses-native-library) in its own manifest.
  • A verified .tflite model 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 CompiledModel instance. Creation, inference, and closing must execute on that same background thread, never on the main thread.
  • Buffer lifecycle : Allocate TensorBuffer instances once using createInputBuffers and createOutputBuffers, reuse them across inferences, and close all input and output buffers before closing the CompiledModel.
  • Synchronous timing : model.run enqueues work on the GPU and returns before GPU execution completes. Always measure model.run and output buffer readback (outputs[0].readFloat) together.
  • Warm-up and exception safety : Execute one warm-up inference inside the helper constructor's init block so first-run GPU shader compilation doesn't block the first user interaction, and call close in catch before rethrowing so neither CompiledModel nor TensorBuffer handles 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.lite code, you must read the "Migrating from legacy TFLite Interpreter" section in full before you edit any file. Migrated code must not import any org.tensorflow.lite class (including DataType), every legacy GPU choice (GpuDelegate, or the Support library's Model.Device.GPU) becomes CompiledModel.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 Environment replaces the environment property of Step 2. Use version 17.0.0 exactly, and run `./gradlew assembleD
자주 묻는 질문

어떤 런타임을 써야 하나요?

스킬이 기본값인 Google Play 서비스 런타임과 번들 런타임 중에서 고르도록 요청합니다.

필요한 최소 Android 버전은 무엇인가요?

LiteRT 라이브러리 요구 사항에 따라 프로젝트의 minSdk는 24 이상이어야 합니다.

이전 TensorFlow Lite Interpreter를 쓰나요?

아니요. 이 스킬은 사용하지 않도록 된 API를 쓰지 말라고 하며, 대신 CompiledModel을 사용합니다.

상세 정보

작성자의 원본 설명

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 r

repo: android/skills

인기도

GitHub 스타
10k
순위
#11912
라이선스
Apache-2.0
업데이트
2026. 10. 29.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬