Enable the Android NPU in your app
Package the Google Tensor dispatch library, load a compiled LiteRT-LM bundle, and verify per-turn NPU participation.
On this page
Requirements#
-
An Android arm64 app with native LiteRT-LM enabled. The pinned
litert-lm-native runtime provides NPU placement ABI 1. Custom runtimes need
v0.20.0-1or newer with that ABI. -
A
.litertlmbundle compiled for the device's SoC and a matching vendor dispatch library implementing LiteRT dispatch interface ABI 1. -
The qualified setup uses Google Tensor G6 and
Gemma 4 E2B compiled for Tensor G6. Testing covered Android API 37.
Choose the
gemma-4-E2B-it_Google_Tensor_G6.litertlmvariant. Verify the download against SHA-256d6cbe8d625f4965a8c32565f65ae774d19598d0d967a4c2101a7e04988daaf58. The generic Gemma 4 E2B bundle is suitable for CPU or GPU.
Package the Tensor dispatch library#
Google documents install-time Play Feature Delivery for Android NPU runtime
libraries. Starting with LiteRT 2.3.0, Google publishes those libraries as
Maven packages, including
com.google.ai.edge.litert:litert-npu-runtime-google-tensor:<VERSION>.
For Tensor, Google's example registers
:litert_npu_runtime_libraries:google_tensor_runtime as a dynamic feature and
adds :litert_npu_runtime_libraries:runtime_strings as a project dependency.
It configures device targeting, minSdk = 31, and the arm64-v8a
ABI filter.
The example shows useLegacyPackaging = true for the Qualcomm runtime
libraries. See Google's Play Feature Delivery setup.
Install-time split tested with bundletool#
On a Tensor G6 DDP Pixel 11 Pro, bundletool install-apks simulated
install-time delivery of the Tensor dynamic feature. With native-library
extraction enabled (useLegacyPackaging = true), Android extracted
libLiteRtDispatch_GoogleTensor.so from
split_google_tensor_runtime.config.arm64_v8a.apk alongside the base
libLiteRtLm.so. The base and feature contexts reported the same
ApplicationInfo.nativeLibraryDir. Passing either directory value as
dispatchLibDir produced a turn that reported participated, as did the
base-bundled control.
With extraction disabled, both contexts reported the same empty directory.
The base directory input, the feature directory input, and the APK-backed
directory input ending in
split_google_tensor_runtime.config.arm64_v8a.apk!/lib/arm64-v8a each threw
LlamaUnsupportedException with zero output.
The test covered local installation on one device. Play Console delivery, Play's device-group assignment, and other vendors remain untested. See issue #2549 for the test results and scope.
App-packaged dispatch (qualified Studio setup)#
Resolve com.google.ai.edge.litert:litert-npu-runtime-google-tensor:2.4.1@aar
from Google Maven in a non-transitive Gradle configuration. The AAR ships
LICENSE and THIRD_PARTY_NOTICE.txt, which cover several licenses,
including GPL-2.0 text. Review both files yourself before distributing your
app, and ship them unmodified with the dispatch library. This is packaging
guidance and does not constitute legal advice.
The worked example below uses the same input files and Android packaging
settings as the Studio bundling in PR #2467. The
application owns the dispatch packaging. Core llamadart supplies the LiteRT-LM
runtime. Studio resolves and verifies the AAR and the three extracted entries
in a Gradle task before registering the generated JNI and asset directories.
With google() in your project's dependency repositories, this app-module
build.gradle.kts excerpt resolves the same archive for manual staging:
val googleTensorAar by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
isTransitive = false
}
dependencies {
googleTensorAar("com.google.ai.edge.litert:litert-npu-runtime-google-tensor:2.4.1@aar")
}
tasks.register("printGoogleTensorAar") {
inputs.files(googleTensorAar)
doLast { println(googleTensorAar.singleFile.absolutePath) }
}
Run ./gradlew -q :app:printGoogleTensorAar from the Android project.
Before staging, verify the resolved AAR's SHA-256 is
944aadafc6b362aa7fbb5467528d3d579c641e35cb056b5bbace854e816370a7.
From your Android app module, extract the dispatch into the arm64 JNI directory
and the notices into assets:
# Set aar to the path of the resolved 2.4.1 AAR.
mkdir -p src/main/jniLibs/arm64-v8a src/main/assets/llamadart_notices/google_tensor
unzip -p "$aar" jni/arm64-v8a/libLiteRtDispatch_GoogleTensor.so \
> src/main/jniLibs/arm64-v8a/libLiteRtDispatch_GoogleTensor.so
for notice in LICENSE THIRD_PARTY_NOTICE.txt; do
unzip -p "$aar" "$notice" > "src/main/assets/llamadart_notices/google_tensor/$notice"
done
In the app module's build.gradle.kts, enable extraction so LiteRT can find the
dispatch as a file in Android's installed native library directory. Preserve
the original dispatch bytes during packaging.
android {
packaging.jniLibs.useLegacyPackaging = true
packaging.jniLibs.keepDebugSymbols += "**/libLiteRtDispatch_GoogleTensor.so"
}
Android provides the Edge TPU libraries. Declare them as optional children of
<application> in AndroidManifest.xml so the app can still install on devices
that lack them.
<uses-native-library android:name="libedgetpu_litert.so" android:required="false" />
<uses-native-library android:name="libedgetpu_util.so" android:required="false" />
Build an arm64 APK and verify its manifest has extractNativeLibs=true and its
archive contains the dispatch and both notices. When using this app-packaged
setup with an app bundle, verify both in the installed splits. In your
Android app code, read
applicationContext.applicationInfo.nativeLibraryDir. In Flutter, return this
value to Dart through a platform channel and pass the directory itself as
dispatchLibDir.
Load and verify a turn#
Call this function with the downloaded bundle's local path and Android's
nativeLibraryDir. LiteRtLmModelParams is a ModelParams
specialization.
import 'package:llamadart/llamadart.dart';
Future<void> runNpuTurn(String modelPath, String nativeLibraryDir) async {
final engine = LlamaEngine(LlamaBackend());
try {
await engine.setModel(
LlamaModel(ModelSource.path(modelPath)),
params: LiteRtLmModelParams(
device: ComputeDevice.npu,
contextSize: 4096,
dispatchLibDir: nativeLibraryDir,
),
);
await for (final chunk in engine.create(const [
LlamaChatMessage.fromText(
role: LlamaChatRole.user,
text: 'What is 2 + 2? Reply with just the number.',
),
], params: const GenerationParams(maxTokens: 32))) {
if (chunk.text.isNotEmpty) print(chunk.text);
}
} on LlamaUnsupportedException catch (error) {
print(error.message);
} finally {
try {
print((await engine.getLoadReport())?.liteRtLmNpuPlacement);
} finally {
await engine.dispose();
}
}
}
Read (await engine.getLoadReport())?.liteRtLmNpuPlacement again after each
turn. The report separates compatibility, engine, and turn:
| Observation | Meaning |
|---|---|
| Unverified |
A load can be provisional until deferred initialization.
devicePlacementUnverified
marks unconfirmed admission. A turn of
none
or
pending
has no positive execution evidence.
|
compatible and admitted |
The runtime found a compatible setup and compiled at least one NPU partition for the primary text model. |
participated |
The runtime observed at least one NPU invocation in a successful primary-model send. CPU partition coverage and vision or audio encoder placement remain unknown. |
| Refused | Initialization or a completed send could not establish required placement. Inspect the exception and any available placement report. |
Explicit NPU buffers output until the completed turn confirms participation.
Cancelled turns release no output. To let a user retry on CPU or GPU, load
with that device explicitly and omit dispatchLibDir.
Diagnose a refusal#
These conditions throw LlamaUnsupportedException. Deferred engine
initialization can surface a refusal on first use after setModel succeeds.
| Condition | Diagnostic |
|---|---|
| Legacy C API | The selected legacy C API does not report placement. Use the pinned runtime. |
| Missing or mismatched placement ABI | The runtime names a missing export or reports its unsupported ABI version. Use placement ABI 1. |
| Missing dispatch directory or library |
Preflight reports
unavailable
compatibility. Check the installed JNI file and directory passed to Dart.
|
| Incompatible dispatch or environment |
Preflight can report
unsupportedProtocol
for a dispatch interface mismatch, or
incompatible
for a model or environment mismatch. Check the driver, SoC and compiled bundle.
|
| Generic Gemma 4 E2B with valid Tensor dispatch |
The qualification probe reported
resolvedElsewhere
engine placement and
incompatible
compatibility. Use the Tensor G6 build of the bundle.
|
| Completed turn without participation |
The error names the observed turn state, such as
cpuFallback
or
none
. No output is released.
|
Device evidence#
Android NPU qualification covers short text turns using the Tensor G6 Gemma 4 E2B bundle on the Pixel 11 Pro. The runtime owner's placement report showed participation, including after reload and after recovery from cancellation. Edge TPU firmware activity corroborated those turns. An independent per-turn completed-call counter was unavailable. Studio testing used an Android Debug qualification certificate, with ordinary release-signed verification still pending. The Pixel 9 Pro's Tensor G4 was refused by the Studio model gate. See the core placement PR and Studio distribution PR.
Other SoCs and vendor paths remain unsupported and unqualified, including Qualcomm, MediaTek, and Intel OpenVINO on Windows.