litert-lm
Skill này làm gì
Skill này hướng dẫn xây dựng ứng dụng Android chạy trực tiếp một mô hình ngôn ngữ văn bản mở trên điện thoại, dùng CPU hoặc GPU. Nó dành cho lập trình viên Android muốn thêm tính năng trò chuyện, tóm tắt hoặc trích xuất chạy ngay trên thiết bị.
Khi nào nên dùng
- ✓Khi bạn muốn tính năng trò chuyện hoặc tóm tắt trong ứng dụng Android chạy ngay trên điện thoại.
- ✓Khi bạn định dùng một mô hình .litertlm như Gemma, Qwen, Llama hoặc Phi từ Hugging Face.
- ✓Khi bạn cần thiết lập Gradle và các cài đặt GPU cho một mô hình ngôn ngữ chạy trên thiết bị.
Liên kết skill
https://github.com/android/skills/blob/main/device-ai/litert/litert-lm/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Thêm tính năng trò chuyện chạy trên thiết bị vào ứng dụng Android của tôi bằng mô hình Gemma.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill hướng dẫn thêm thư viện LiteRT-LM, thiết lập các mục GPU trong manifest và tải file mô hình được lưu trên thiết bị. Sau đó nó chỉ cách chạy mô hình trong ứng dụng.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
This skill provides step-by-step guidance for building an Android app that runs
an open text LLM through the LiteRT-LM Kotlin API
(com.google.ai.edge.litertlm) on the CPU or the GPU. The model is one
.litertlm file. Images, audio, tool calling, and NPU backends aren't covered.
For vision and audio models with .tflite files, suggest the litert-runtime
skill.
When a LiteRT-LM class or method that this skill uses doesn't compile, you must read the LiteRT-LM Android guide and the LiteRT-LM README before changing the code.
Prerequisites
- A Kotlin Android project (the Android Studio Empty Activity template is enough). The
litertlm-android0.18.0 AAR declaresminSdk24. - The dependency in the app-level
build.gradle.ktsfile from Google Maven:implementation("com.google.ai.edge.litertlm:litertlm-android:0.18.0"). Google Maven lists the later releases. - For the GPU backend, two
uses-native-libraryentries inside<application>inAndroidManifest.xml. Add theINTERNETpermission if the app downloads the model. - The model file lives on the device's file system (hundreds of MB to a few GB), never in
assets/or in the APK.
Critical mandates
- Dependency first : Before writing code that imports
com.google.ai.edge.litertlm, add thelitertlm-androiddependency from Step 1 if the project lacks it. Verify with./gradlew assembleDebug. - Background initialization :
Engine(config).initialize()loads the weights and blocks for seconds. Call it on a background thread, never on the main thread. - Single owner : One single-thread executor owns the
Engineand theConversation. Creation, streaming, cancellation, and closing run on it. - Close once :
EngineandConversationareAutoCloseable. A secondcloseon either throwsIllegalStateException. So doescloseon an engine whoseinitializethrew. Store the engine only afterinitializereturns. - Model outside the APK : Pass an absolute path to
EngineConfig. Never bundle a.litertlmfile inassets/.
Detailed steps
Step 1: Configure Gradle and the manifest
Search the project for libs.versions.toml, app/build.gradle.kts, and
AndroidManifest.xml before editing build files. Configure minSdk and add the
LiteRT-LM dependency in app/build.gradle.kts:
android {
defaultConfig {
minSdk = 24
}
}
dependencies {
implementation("com.google.ai.edge.litertlm:litertlm-android:0.18.0")
}
If the project uses Hilt, check the Dagger version first. litertlm-android
0.18.0 carries Kotlin 2.4 metadata, which Hilt 2.59.2 can't read. The build
then fails in hiltJavaCompileDebug with Provided Metadata instance has version 2.4.0, while maximum supported version is 2.3.0. Pick one fix:
- Path A : Upgrade the Hilt version (
com.google.dagger) to 2.60.1 or later. Ask the user before editinggradle/libs.versions.toml. - Path B : Keep the Hilt version and add a later version of the metadata reader to the annotation processor path in
app/build.gradle.kts:
dependencies {
ksp("org.jetbrains.kotlin:kotlin-metadata-jvm:2.4.21")
}
For the GPU backend, add both lines inside <application> in
AndroidManifest.xml. Add the INTERNET permission outside <application>
when the app downloads the model:
<uses-permission android:name="android.permission.INTERNET"/>
<application>
<uses-native-library
android:name="libvndksupport.so"
android:required="false"/>
<uses-native-library
android:name="libOpenCL.so"
android:required="false"/>
</application>
Step 2: Pick a model from litert-community
Choose a .litertlm file from litert-community on Hugging Face. Start with
litert-community/gemma-4-E2B-it-litert-lm (the file gemma-4-E2B-it.litertlm,
2.6 GB). For a 0.6 GB model, start with litert-community/Qwen3-0.6B (the file
Qwen3-0.6B.litertlm). Both files run on the CPU and the GPU. A SoC suffix such
as _Google_Tensor_G5 or .mediatek.mt6993 marks an NPU build, which this
skill doesn't cover. The model card names the tested backends and the size.
You must read get a model before you choose a model file other than these two, before you writ
Câu hỏi thường gặp
File mô hình có thể được đóng gói bên trong ứng dụng không?
Không. File mô hình phải nằm trên bộ nhớ của thiết bị, không nằm trong assets hay gói của ứng dụng.
Nó có hỗ trợ hình ảnh hoặc âm thanh không?
Không. Nó chỉ bao quát mô hình văn bản. Mô hình thị giác và âm thanh thuộc về một skill khác.
Nó hoạt động với những mô hình nào?
Nó nhắm tới các mô hình văn bản mở ở định dạng .litertlm, chẳng hạn Gemma, Qwen, Llama và Phi.
Chi tiết
Mô tả gốc của tác giả
Builds an Android app that runs an open text LLM on the device, on the CPU or the GPU, with the LiteRT-LM Kotlin API (com.google.ai.edge.litertlm:litertlm-android). Use this skill when creating a chat, summarization, or extraction feature with a .litertlm model from Hugging Face litert-community (Gemma, Qwen, Llama, Phi), including the Gradle dependency, the GPU manifest entries, getting the model file onto the device, Engine initialization off the main thread, a streamed multi-turn Conversation with sendMessageAsync, and the AndroidViewModel and Compose screen. Don't use for running .tflite v
repo: android/skills
Độ phổ biến
- Sao GitHub
- 10k
- Vị trí xếp hạng
- #11911
- Giấy phép
- Apache-2.0
- Cập nhật
- 29/10/2026
Bình luận
- …
Thêm skill từ kho mã này
agp-9-upgrade
10kGiúp agent của bạn nâng cấp ứng dụng Android lên Android Gradle Plugin 9 và xử lý các thay đổi gây lỗi. Không dành cho dự án đa nền tảng.
camerax
10kGiúp agent của bạn xây dựng các tính năng camera Android bằng CameraX, gồm quay video, điều khiển phần cứng, ML Kit và hiệu ứng Media3.
android-for-cars-parked-apps
10kĐiều chỉnh một ứng dụng video, trò chơi hoặc trình duyệt Android để chạy như ứng dụng khi xe đỗ trên Android Auto và Android Automotive.
appfunctions
10kTìm các luồng công việc chính trong ứng dụng Android và công khai chúng dưới dạng AppFunctions để agent AI và lệnh giọng nói có thể chạy.
Skill tương tự
android-clean-architecture
280kGiúp agent của bạn tổ chức dự án Android hiệu quả, cấu trúc code để việc bảo trì và phát triển tính năng mới dễ dàng hơn.
compose-multiplatform-patterns
280kGiúp agent của bạn dùng các mẫu Compose Multiplatform và Jetpack Compose trong dự án KMP, gồm trạng thái, điều hướng, giao diện và hiệu năng.
dart-flutter-patterns
280kGiúp agent của bạn viết code cho ứng dụng Dart và Flutter. Agent dùng các mẫu hiện đại để tạo ứng dụng vững chắc và dễ quản lý.