<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5" -->

---
title: On-Device AI Series (Part 5): LiteRT-LM | daily.dev
description: A deep, hands-on walkthrough of Google's LiteRT-LM runtime for running LLMs like Gemma, Qwen, Llama, and Phi on Android devices. Covers the Engine/Session...
canonical: https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: On-Device AI Series (Part 5): LiteRT-LM | daily.dev
og:description: A deep, hands-on walkthrough of Google's LiteRT-LM runtime for running LLMs like Gemma, Qwen, Llama, and Phi on Android devices. Covers the Engine/Session...
og:url: https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5
og:image: https://api.daily.dev/og/posts/TstGy0fH5.png
og:image:alt: On-Device AI Series (Part 5): LiteRT-LM
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# On-Device AI Series (Part 5): LiteRT-LM

**[ProAndroidDev](https://daily.dev/sources/pand)** · 14 min read · 0 upvotes · 0 comments

## Summary

A deep, hands-on walkthrough of Google's LiteRT-LM runtime for running LLMs like Gemma, Qwen, Llama, and Phi on Android devices. Covers the Engine/Session model, streaming responses, hand-building system prompts and tool calling from raw text, multimodal input via the Conversation API, thinking mode, and CPU-vs-GPU benchmarking (Gemma E2B-it showed ~34% faster generation and ~72% throughput speedup on GPU vs CPU). Flags a native library collision between litert and litertlm-android AARs that causes a SIGSEGV, along with a list of anti-patterns around token budgeting, sampler configuration, and session reuse. Rates the API 7/10 overall, citing strong offline capability and performance controls but weaker documentation and non-idiomatic Kotlin callback design.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://proandroiddev.com/on-device-ai-series-part-5-litert-lm-d6c23b102094>

## Questions this post answers

### What does maxNumTokens actually control in LiteRT-LM's EngineConfig?

It sets the combined input plus output token budget, functioning as the KV-cache ceiling rather than an output-only limit. Copying a tutorial's small default can cause a crash once a loaded chat's prefill replay outgrows it. A value of 16,384 worked for Gemma 4 in one implementation, though the right ceiling is model-dependent and must be rechecked per model.

_Developers sizing token budgets for on-device chat apps can track LiteRT-LM implementation details on daily.dev._

### Why does my app crash with a SIGSEGV in nativeCreateEngine when using LiteRT-LM on Android?

Both the litert and litertlm-android AARs bundle a native library named libLiteRtClGlAccelerator.so, and the versions are not interchangeable, so using the wrong one alongside liblitertlm_jni.so triggers a SIGSEGV in nativeCreateEngine. The fix is in Gradle packaging, not application code: extract the matching .so from the litertlm-android AAR into generated jniLibs, relying on source-set precedence and pickFirsts as a fallback.

_Android engineers debugging native library conflicts in AI runtimes can find similar gotchas curated on daily.dev._

### How much faster is GPU than CPU for running Gemma E2B-it locally on Android with LiteRT-LM?

GPU execution completed generation in 9.5 seconds versus 14.4 seconds on CPU, roughly 34% faster overall, with throughput rising from 2.9 tokens per second on CPU to 5.0 tokens per second on GPU, about a 72% speedup. Exact numbers depend on hardware, but GPU acceleration consistently yields significant gains, with even sharper improvements expected on dedicated NPUs.

_Teams benchmarking on-device LLM backends can compare real throughput numbers surfaced on daily.dev._

## Similar posts on daily.dev

- [I turned my phone into a local LLM server, and it handles vision, voice, and tool calls](https://daily.dev/posts/i-turned-my-phone-into-a-local-llm-server-and-it-handles-vision-voice-and-tool-calls-f2fcaxaha) · XDA Developers · 0 upvotes · 0 comments
- [LiteRT: The Universal Framework for On-Device AI](https://daily.dev/posts/litert-the-universal-framework-for-on-device-ai-dkvzmc8hv) · Google Developers · 0 upvotes · 0 comments
- [Benchmark LLMs on-device with AI Edge Portal](https://daily.dev/posts/benchmark-llms-on-device-with-ai-edge-portal-b3cgdz9pt) · Google Cloud · 1 upvotes · 0 comments

---

Tags: [#android](https://daily.dev/tags/android), [#kotlin](https://daily.dev/tags/kotlin), [#local-ai](https://daily.dev/tags/local-ai), [#gemma](https://daily.dev/tags/gemma)

[View this post on daily.dev](https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"On-Device AI Series (Part 5): LiteRT-LM","url":"https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5"},"datePublished":"2026-09-14T06:07:14.316Z","dateModified":"2026-09-14T22:20:14.540Z","description":"A deep, hands-on walkthrough of Google's LiteRT-LM runtime for running LLMs like Gemma, Qwen, Llama, and Phi on Android devices. Covers the Engine/Session...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/651852a0975c28ba0de8cfacd3cc38f0?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/651852a0975c28ba0de8cfacd3cc38f0?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"ProAndroidDev","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"ProAndroidDev","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/656c1eb1f1ef4f91936e86fc16545114","url":"https://daily.dev/sources/pand"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"android,kotlin,local-ai,gemma","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"ProAndroidDev","item":"https://daily.dev/sources/pand"},{"@type":"ListItem","position":3,"name":"On-Device AI Series (Part 5): LiteRT-LM"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/on-device-ai-series-part-5-litert-lm-tstgy0fh5#faq","mainEntity":[{"@type":"Question","name":"What does maxNumTokens actually control in LiteRT-LM's EngineConfig?","acceptedAnswer":{"@type":"Answer","text":"It sets the combined input plus output token budget, functioning as the KV-cache ceiling rather than an output-only limit. Copying a tutorial's small default can cause a crash once a loaded chat's prefill replay outgrows it. A value of 16,384 worked for Gemma 4 in one implementation, though the right ceiling is model-dependent and must be rechecked per model. Developers sizing token budgets for on-device chat apps can track LiteRT-LM implementation details on daily.dev."}},{"@type":"Question","name":"Why does my app crash with a SIGSEGV in nativeCreateEngine when using LiteRT-LM on Android?","acceptedAnswer":{"@type":"Answer","text":"Both the litert and litertlm-android AARs bundle a native library named libLiteRtClGlAccelerator.so, and the versions are not interchangeable, so using the wrong one alongside liblitertlm_jni.so triggers a SIGSEGV in nativeCreateEngine. The fix is in Gradle packaging, not application code: extract the matching .so from the litertlm-android AAR into generated jniLibs, relying on source-set precedence and pickFirsts as a fallback. Android engineers debugging native library conflicts in AI runtimes can find similar gotchas curated on daily.dev."}},{"@type":"Question","name":"How much faster is GPU than CPU for running Gemma E2B-it locally on Android with LiteRT-LM?","acceptedAnswer":{"@type":"Answer","text":"GPU execution completed generation in 9.5 seconds versus 14.4 seconds on CPU, roughly 34% faster overall, with throughput rising from 2.9 tokens per second on CPU to 5.0 tokens per second on GPU, about a 72% speedup. Exact numbers depend on hardware, but GPU acceleration consistently yields significant gains, with even sharper improvements expected on dedicated NPUs. Teams benchmarking on-device LLM backends can compare real throughput numbers surfaced on daily.dev."}}]}
```

