Ship an LLM in an Android App
Kotlin with Compose and MediaPipe, React Native with llama.rn, hardware acceleration and NPU verification
01
What changes after this course
- ●Instead of a model that runs only in a notebook, you ship an on-device LLM feature in an Android or React Native app
- ●Instead of choosing native or cross-platform by preference, you choose after building both
- ●Instead of assuming the NPU does the work, you prove it from logcat
02
Why it matters now
A model that runs in a notebook is not an app. Threading, lifecycle, memory and cancellation are what break on a real phone, and the narration names which parts of the sample code must be fixed before you ship. The appendix moves to Gemma 4, released under Apache-2.0, which drops the licence duties Gemma 2 puts on your app.
03
What you leave with
- ✓An Android native project and a React Native project
- ✓Four notebooks, including the Gemma 4 and LiteRT-LM upgrade
- ✓A LICENSES.md that lists what Gemma 2 requires you to build into the app
04
Skills you'll build
- →Integrate an on-device LLM in Kotlin and Compose with MediaPipe and a foreground service
- →Integrate the same model in React Native with llama.rn, with download and streaming
- →Build on-device RAG with a SQLite vector store and verify from logcat that the NPU does the work
Inside the course
Screens from the lectures. The notebooks and Kotlin files on screen are the ones you download; their tables are reference figures, not results measured in the video. MediaPipe, ONNX Runtime, llama.rn and LiteRT-LM are open third-party tools.

android-native/app/src/main/java/com/example/edgeai/LlmEngine.kt
MediaPipe tokens as a Kotlin Flow
The engine wrapper turns MediaPipe's partial-result callback into a Flow your Compose UI can collect. awaitClose closes the session when the screen stops listening.
▶ Lecture 1.1 · part4 kickoff project gradle and mediapipe engine
android-native/app/src/main/java/com/example/edgeai/VectorStore.kt
On-device RAG with a plain SQLite table
Embeddings are stored as blobs in a SQLite chunks table and ranked by dot product, top 3 by default. No vector database to install on the phone.
Lecture 1.3 · on device rag debugging and fix list

notebooks/11b_rn_llm_integration.ipynb
Five failures, each with a cause and a fix
Android OOM, iOS Metal init failure, a slow first token, JS thread freezes and background stops on iOS. Each row names the cause and the fix to try first.
Lecture 2.2 · usechat hook screen running and issues

android-native/app/src/main/java/com/example/edgeai/OrtSessionFactory.kt
Try the NPU first, fall back on failure
The session factory tries QNN, then NNAPI, then CPU, and logs which execution provider created the session. If one fails to load, it tries the next.
Lecture 3.1 · part5 kickoff backend matrix ep fallback qnn jni

notebooks/13a_native_hw_acceleration.ipynb
Read the logs to see what ran on the NPU
Example logcat patterns for three outcomes: 152 of 168 nodes on NNAPI, a partial offload at 53% coverage, and a full fall back to the CPU. The notes warn that below 50% coverage it can be slower than the CPU alone.
Lecture 3.3 · npu offload verification ep status tuning targets

notebooks/11c_gemma4_upgrade.ipynb
What the Gemma 4 upgrade costs on a phone, per the notebook's table
Gemma 4 E2B brings a 32k+ context and native tool calling, but the INT4 file grows from 1.6 GB to 2.6 GB and the minimum RAM from 4 GB to 8 GB.
Lecture 4.1 · appendix gemma4 e2b litert lm and downloader
What you'll learn
- ✓Integrate an on-device LLM in a Kotlin/Compose app with MediaPipe and a foreground service
- ✓Integrate the same model in React Native with llama.rn, including model download and streaming
- ✓Build an on-device RAG pipeline with embeddings and a SQLite vector store
- ✓Use execution-provider fallback, profile with Android Studio Profiler and Perfetto, and verify NPU offload
- ✓Spot and fix the threading, lifecycle and memory mistakes that make on-device AI apps fail
About this course
A model that runs in a notebook is not an app. This course puts a quantized language model inside a real Android application — twice, in two stacks — and is explicit about everything that breaks on a real phone.
Track A is Kotlin: project and Gradle setup, a MediaPipe LLM engine wrapper, a ViewModel, a Jetpack Compose chat screen, a foreground service that keeps generating in the background, model files in assets, and an on-device RAG pipeline with embeddings and a SQLite vector store. Track B is React Native with llama.rn: project setup, Metro configuration for large model files, an LLM service module, a model downloader with progress, and a streaming chat hook and screen. Then hardware acceleration: the execution-provider fallback chain, calling Qualcomm QNN through JNI, profiling with Android Studio Profiler and Perfetto, and verifying from logcat that the NPU is really doing the work. An appendix covers migrating to Gemma 4 and LiteRT-LM with native tool calling.
The code is walked through by intent — threading, lifecycle, memory, cancellation — and the narration says out loud which parts of the sample code must be fixed before you ship, which makes them the real exercises of the course.
**Licensing.** Getting weights onto a user's phone is redistribution, so this course ships a `Resources/LICENSES.md` with every asset checked against its actual licence text. **Gemma 2, used in Track A and Track B, is commercially usable but obliges you to give every user a copy of the Gemma Terms of Use, reproduce its notice string verbatim, and carry its Prohibited Use Policy into your own terms** — all of which are things you build into the app, not paperwork you do afterwards. The Section 4 appendix moves to Gemma 4, which Google released under Apache-2.0 and which drops those obligations entirely.
Curriculum5 sections · 14 lectures · 1h 42m
Section 0. Welcome
Free previewSection 1. Track A Native Android LLM App
Free preview- ▶section 1 intro0:06
- ▶part4 kickoff project gradle and mediapipe engine9:00
- 🔒viewmodel compose ui foreground service9:18
- 🔒on device rag debugging and fix list10:30
Section 2. Track B React Native LLM App
- 🔒why llama rn setup metro service download9:00
- 🔒usechat hook screen running and issues8:18
Section 3. Hardware Acceleration and NPU Verification
- 🔒section 3 intro0:12
- 🔒part5 kickoff backend matrix ep fallback qnn jni9:12
- 🔒android studio profiler perfetto benchmark gauge7:48
- 🔒npu offload verification ep status tuning targets9:36
Section 4. Appendix Gemma 4 and LiteRT-LM
- 🔒appendix gemma4 e2b litert lm and downloader8:48
- 🔒appendix dual gemma engine and chat templates8:12
- 🔒appendix tool calling agent migration checklist adoption11:18
Requirements
- · A computer with Python 3.10+ (a free Google Colab account is enough for most sessions)
- · Comfort reading Python code; you do not need to be an expert
- · A quantized model in GGUF or ONNX form (our Model Preparation course, or your own)
- · Android Studio (Track A) and/or a React Native toolchain (Track B)
- · Kotlin or TypeScript basics; you can follow one track only
- · Willingness to read `Resources/LICENSES.md`: shipping Gemma 2 obliges you to pass its Terms and Prohibited Use Policy on to your users
Who this is for
- · Android and React Native developers adding on-device AI features
- · ML engineers who need to ship a model inside an app, not a server
- · Teams choosing between a native and a cross-platform stack
Read alongside the course
The voice-over in this course is synthesized with a text-to-speech model from scripts written and reviewed by the instructor, and the on-screen material (notebooks, code, slides) is the instructor's own work.