litert-lm
Was er macht
Dieser Skill begleitet den Bau einer Android-App, die ein offenes Textmodell direkt auf dem Telefon ausführt, auf der CPU oder GPU. Er ist für Android-Entwickler gedacht, die eine Chat-, Zusammenfassungs- oder Extraktionsfunktion einbauen, die auf dem Gerät selbst läuft.
Wann du ihn nutzt
- ✓Wenn du in einer Android-App eine Chat- oder Zusammenfassungsfunktion willst, die auf dem Telefon selbst läuft.
- ✓Wenn du ein .litertlm-Modell wie Gemma, Qwen, Llama oder Phi von Hugging Face nutzen willst.
- ✓Wenn du die Gradle-Einrichtung und GPU-Einstellungen für ein Sprachmodell auf dem Gerät brauchst.
Link zum Skill
https://github.com/android/skills/blob/main/device-ai/litert/litert-lm/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Füge meiner Android-App mit einem Gemma-Modell eine Chatfunktion hinzu, die auf dem Gerät läuft.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Skill führt durch das Hinzufügen der Bibliothek LiteRT-LM, das Setzen der GPU-Einträge im Manifest und das Laden einer Modelldatei aus dem Gerätespeicher. Danach zeigt er, wie das Modell in der App läuft.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
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
Häufige Fragen
Kann die Modelldatei in die App eingepackt werden?
Nein. Die Modelldatei muss im Speicher des Geräts liegen, nicht in den Assets oder im Paket der App.
Unterstützt er Bilder oder Audio?
Nein. Er deckt nur Textmodelle ab. Bild- und Audiomodelle gehören zu einem anderen Skill.
Mit welchen Modellen funktioniert er?
Er ist für offene Textmodelle im Format .litertlm gedacht, etwa Gemma, Qwen, Llama und Phi.
Details
Originalbeschreibung des Autors
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
Beliebtheit
- GitHub-Sterne
- 10k
- Platz im Ranking
- #11911
- Lizenz
- Apache-2.0
- Aktualisiert
- 29.10.2026
Kommentare
- …
Weitere Skills aus diesem Repository
agp-9-upgrade
10kHilft deinem Agenten, eine Android-App auf Android Gradle Plugin 9 zu aktualisieren und die Breaking Changes abzuarbeiten. Nicht für Multiplattform-Projekte.
camerax
10kHilft deinem Agenten, Kamerafunktionen für Android mit CameraX zu bauen, einschließlich Videoaufnahme, Hardwaresteuerung, ML Kit und Media3-Effekten.
android-for-cars-parked-apps
10kHilft deinem Agenten, eine Android-Video-, Spiele- oder Browser-App so anzupassen, dass sie als geparkte App in Android Auto und Android Automotive läuft.
appfunctions
10kHilft deinem Agenten, in einer Android-App wichtige Abläufe zu finden und sie als AppFunctions bereitzustellen, die KI-Agenten und Sprachbefehle ausführen können.
Ähnliche Skills
android-clean-architecture
280kLässt deinen Agenten Android-Projekte effizient strukturieren. Der Code wird so organisiert, dass Wartung und neue Features leichter werden.
compose-multiplatform-patterns
280kHilft deinem Agenten, Compose Multiplatform und Jetpack Compose Patterns in KMP-Projekten einzusetzen. Abgedeckt sind State, Navigation, Theming und Performance.
dart-flutter-patterns
280kLässt deinen Agenten Code für Dart- und Flutter-Apps schreiben. Er nutzt moderne Patterns für robuste und gut wartbare Apps.