Aller au contenu
Skillpedia
Applis mobiles10k · #11911

litert-lm

Ce qu’il fait

Ce skill guide la création d'une application Android qui exécute directement sur le téléphone un modèle de langage textuel ouvert, sur le processeur ou le processeur graphique. Il s'adresse aux développeurs Android qui ajoutent une fonction de chat, de résumé ou d'extraction fonctionnant sur l'appareil lui-même.

Quand l’utiliser

  • ✓Quand vous voulez un chat ou un résumé dans une application Android qui tourne sur le téléphone lui-même.
  • ✓Quand vous prévoyez d'utiliser un modèle .litertlm comme Gemma, Qwen, Llama ou Phi depuis Hugging Face.
  • ✓Quand vous avez besoin de la configuration Gradle et des réglages GPU pour un modèle de langage sur l'appareil.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/android/skills/blob/main/device-ai/litert/litert-lm/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Ajoute une fonction de chat sur l'appareil à mon application Android avec un modèle Gemma.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

Le skill décrit l'ajout de la bibliothèque LiteRT-LM, la configuration des entrées GPU dans le manifeste et le chargement d'un fichier de modèle stocké sur l'appareil. Il montre ensuite comment exécuter le modèle dans l'application.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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-android 0.18.0 AAR declares minSdk 24.
  • The dependency in the app-level build.gradle.kts file 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-library entries inside <application> in AndroidManifest.xml. Add the INTERNET permission 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 the litertlm-android dependency 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 Engine and the Conversation. Creation, streaming, cancellation, and closing run on it.
  • Close once : Engine and Conversation are AutoCloseable. A second close on either throws IllegalStateException. So does close on an engine whose initialize threw. Store the engine only after initialize returns.
  • Model outside the APK : Pass an absolute path to EngineConfig. Never bundle a .litertlm file in assets/.

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:

<br />
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 editing gradle/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:
<br />
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:

<br />
<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

Questions fréquentes

Le fichier du modèle peut-il être inclus dans l'application ?

Non. Le fichier du modèle doit se trouver sur le stockage de l'appareil, et non dans les ressources ou le paquet de l'application.

Prend-il en charge les images ou l'audio ?

Non. Il ne couvre que les modèles textuels. Les modèles de vision et d'audio relèvent d'un autre skill.

Avec quels modèles fonctionne-t-il ?

Il vise les modèles textuels ouverts au format .litertlm, comme Gemma, Qwen, Llama et Phi.

Détails

Description originale de l’auteur

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

Popularité

Étoiles GitHub
10k
Position au classement
#11911
Licence
Apache-2.0
Mis à jour
29/10/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires