litert-runtime
Fungsinya
Skill ini memandu penambahan machine learning di perangkat ke aplikasi Android dengan model .tflite, memakai API CompiledModel dari LiteRT. Skill ditujukan bagi pengembang Android yang menjalankan tugas gambar, audio, atau embedding di ponsel.
Kapan dipakai
- ✓Saat Anda ingin klasifikasi gambar atau model visi lain berjalan di dalam aplikasi Android.
- ✓Ketika Anda perlu mengatur LiteRT di Gradle, memilih antara runtime layanan Play dan runtime bawaan.
- ✓Ketika Anda ingin model .tflite berjalan di GPU dengan cadangan ke CPU.
Link skill
https://github.com/android/skills/blob/main/device-ai/litert/litert-runtime/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Tambahkan klasifikasi gambar dengan model .tflite ke aplikasi Android saya memakai LiteRT di GPU.”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill membantu Anda memilih runtime, menambahkan dependensi Gradle, dan menyiapkan gambar untuk model. Lalu ia menunjukkan cara menjalankan model di GPU dan beralih ke CPU bila diperlukan.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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 (
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 assembleD
Pertanyaan umum
Runtime mana yang sebaiknya saya pakai?
Skill meminta Anda memilih antara runtime layanan Google Play, yang merupakan default, dan runtime bawaan.
Versi Android minimum apa yang dibutuhkan?
minSdk proyek harus 24 atau lebih tinggi, karena pustaka LiteRT memerlukannya.
Apakah ia memakai TensorFlow Lite Interpreter yang lama?
Tidak. Skill menyatakan agar tidak memakai API usang tersebut dan menggunakan CompiledModel sebagai gantinya.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 10k
- Peringkat
- #11912
- Lisensi
- Apache-2.0
- Diperbarui
- 29/10/2026
Komentar
- …
Skill lain dari repositori ini
agp-9-upgrade
10kMembantu agent Anda meningkatkan aplikasi Android ke Android Gradle Plugin 9 dan menangani perubahan yang merusak. Tidak untuk proyek multiplatform.
camerax
10kMembantu agent Anda membangun fitur kamera Android dengan CameraX, termasuk perekaman video, kontrol perangkat keras, serta efek ML Kit dan Media3.
android-for-cars-parked-apps
10kMembantu agent Anda menyesuaikan aplikasi video, game, atau browser Android agar bisa berjalan sebagai aplikasi parkir di Android Auto dan Android Automotive.
appfunctions
10kMembantu agent Anda menemukan alur kerja utama dalam aplikasi Android dan menyediakannya sebagai AppFunctions yang bisa dijalankan agent AI dan perintah suara.
Skill serupa
android-clean-architecture
280kMembuat agent Anda mengatur proyek Android dengan efisien. Struktur kodenya dibuat agar lebih mudah dirawat dan pengembangan fitur baru.
compose-multiplatform-patterns
280kMembantu agent Anda menggunakan pola Compose Multiplatform dan Jetpack Compose di proyek KMP, mencakup state, navigasi, theming, dan performa.
dart-flutter-patterns
280kMembuat agent Anda menulis kode untuk aplikasi Dart dan Flutter. Menggunakan pola modern agar aplikasi kokoh dan mudah dikelola.