r/expo • u/DarkRyoshin17 • 7h ago
Running local GGUF LLMs (Llama 3.2) 100% offline in Expo 52 — Config Plugin setup & handling mobile OOMs
Hey everyone,
A common misconception I kept hearing in the React Native community is that running heavy on-device LLMs (via C++ llama.cpp bindings) requires ejecting into a messy bare workflow and manually hacking Gradle and CMake scripts every time.
Over the past few weeks, I’ve been testing and documenting a turnkey setup running Llama 3.2 (1B/3B) and Qwen 2.5 completely offline inside an Expo 52 project using Custom Development Clients (expo-dev-client) and Continuous Native Generation (prebuild).
Here are the key architecture hurdles and how we solved them for Expo:
- Native C++ Bindings via Config Plugins
Instead of touching native Android/iOS directories manually, we configured llama.rn (llama.cpp C++ bindings) through Expo config plugins.
- On iOS: Podspec configuration targets modern Apple Silicon frameworks (Accelerate and Metal).
- On Android: Custom build properties configure the NDK 26+ toolchain and CMake flags directly through app.json, so running "npx expo prebuild --clean" builds cleanly every time.
2. Model File Management (No binary bloat)
You can't (and shouldn't) bundle a 1.2GB GGUF model file inside your Expo app binary.
- We use expo-file-system to stream and manage local GGUF models directly to the app’s documentDirectory.
- Added checksum verification before loading into memory so corrupted downloads don't trigger native SIGSEGV crashes.
3. Preventing JS Thread Freezing & Thermal Runaway
Running inference on mobile hardware will easily trigger OS memory watchdogs (OOM kills) if peak RAM crosses ~1.2GB.
- Duty-Cycle Throttling: Token generation yields sub-millisecond slices back to the OS, allowing heat dissipation and ensuring the JS bridge and UI animations stay responsive at 60fps.
- Context Size Limits: Bound default context windows to 2048 with 4-bit KV caching, keeping active RAM consumption under ~850MB for 1B Q4_K_M quants.
- Token Checkpointing: Streaming tokens are committed to local SQLite incrementally, so if the app is backgrounded, user session history remains intact.
Real Device Performance (Llama 3.2 1B Q4_K_M):
- iPhone (A16 / A17 Pro): ~16 – 22 tokens/sec
- Snapdragon 8 Gen 2 / Gen 3: ~12 – 18 tokens/sec
- Mid-range (Dimensity 7000 / 8000): ~6 – 10 tokens/sec
The architecture, Expo config plugin examples, and documentation are open on GitHub:
https://github.com/Itsvks17/localai-mobile
Curious to hear from other Expo devs: is anyone else experimenting with local edge AI in Expo 52? How are you handling model downloading and caching strategies in production?

