joshriang
← Back to portfolio

Mobile & Flutter apps·Kotlin·Published

Offline Android AI

I wanted to know what a small language model actually feels like on a phone with no network, so this app runs free small models fully on-device through MediaPipe LLM Inference: a .task file downloads once with WorkManager and OkHttp, then chat works offline. Conversations persist in Room, settings in DataStore, and the model catalog covers Qwen2 1.5B (~1450 MB), SmolLM2 1.7B, Gemma 2 2B, Phi-3 Mini 4K (~2300 MB), StableLM Zephyr 3B and TinyLlama 1.1B (~750 MB) as a low-end fallback. The chat screen streams tokens into a progressively persisted message, the settings screen exposes temperature, top-K, top-P, max-tokens, GPU toggle and a custom .task URL for when a catalog URL 404s, and changing either reloads the engine if the file is present. Because the native backend is single-session, one LlmManager is owned by a process-wide SlmChatApp composition root rather than per screen. Inference needs a physical arm64 device; the emulator only renders the UI, and android:largeHeap is already set.

Date
2026
Main stack
Kotlin
Code
github ↗
01
02
  • The native LLM backend allows one session at a time, so the engine has to be a singleton at the application composition root; creating it in a ViewModel causes the second screen to fail on model load.
  • A 0.7-2.3 GB download belongs in WorkManager with progress surfaced through the manager, not in a coroutine tied to a screen that the user will leave.
  • MediaPipe LLM ships arm64 native libs only, so an x86 emulator crash is expected behaviour and functional testing has to happen on real hardware.
03

Scale 0–100: how much this project relied on each skill.