Enable the Android NPU in your app
Deliver the vendor runtime, probe dispatch availability, and verify LiteRT-LM NPU participation on Android.
On this page
- Requirements
- Deliver the vendor runtime
- On-demand feature modules
- Single-vendor builds outside Play
- Qualcomm (Galaxy S24, SM8650)
- MediaTek (Galaxy Tab S10+, MT6989)
- Vendor licenses and notices
- Probe before downloading the model
- Store the compiled model
- Load and verify a turn
- Diagnose a refusal
- Device evidence
- Google Tensor G3, G4 and G5
- Qualcomm Hexagon HTP for GGUF (Android arm64)
- Requirements and packaging
- Probe and load
- Hexagon device evidence
- Studio internals
Requirements#
-
An Android arm64 app with native LiteRT-LM enabled. The pinned runtime
provides NPU placement ABI 1. Custom runtimes need litert-lm-native
v0.20.0-1or newer with that ABI. -
A
.litertlmbundle compiled for the device's SoC and a vendor dispatch library that implements LiteRT dispatch interface ABI 1. -
The qualified model is
Gemma 4 E2B compiled for Tensor G6
on Android API 37. Use
gemma-4-E2B-it_Google_Tensor_G6.litertlmand verify its SHA-256d6cbe8d625f4965a8c32565f65ae774d19598d0d967a4c2101a7e04988daaf58. The generic Gemma 4 E2B bundle is suitable for CPU or GPU.
Deliver the vendor runtime#
Follow Google's install-time Play Feature Delivery setup.
Use device targeting to deliver one vendor runtime per device. Google
publishes the NPU libraries as Maven packages starting with LiteRT 2.3.0.
For Tensor, Google's sample uses
com.google.ai.edge.litert:litert-npu-runtime-google-tensor:<VERSION>
in the google_tensor_runtime dynamic feature, with the runtime_strings
project dependency. It targets arm64-v8a with minSdk = 31.
Enable native-library extraction in the base app's
android/app/build.gradle.kts. Android reads extractNativeLibs
from
the base APK and applies that setting across the package, including feature
splits. In the AGP 9.3.1 spike, changing useLegacyPackaging in the base
app changed both the base and feature APK manifests. Android package parsing,
native-library extraction.
android {
packaging.jniLibs.useLegacyPackaging = true
}
Preserve dispatcher bytes in the module that packages them.
android {
packaging.jniLibs.keepDebugSymbols += "**/libLiteRtDispatch_*.so"
}
For install-time splits, the probe and model load can discover the
dispatcher automatically when it is extracted alongside libLiteRtLm.so.
Verify the installed files on your target device.
In the local Tensor spike, the APK set was about 281 MB with legacy
packaging disabled and 74.7 MB with it enabled. The base ARM64 APK stored
its JNI entries uncompressed for direct loading in the first build and
deflated them in the second. The feature split's JNI entries were stored
in both builds. These sizes describe local bundletool output.
Spike size report.
For Tensor, the app can request the Android-provided Edge TPU libraries as
optional children of <application> in AndroidManifest.xml.
<uses-native-library android:name="libedgetpu_litert.so" android:required="false" />
<uses-native-library android:name="libedgetpu_util.so" android:required="false" />
On-demand feature modules#
-
After restarting the app. Once the module is installed, call
probeLiteRtLmNpuDispatch()again. Auto-discovery succeeds when the dispatcher is readable alongsidelibLiteRtLm.so. An extracted base directory without a readable dispatcher reportsmissingDispatcher. -
In the running process. Follow Android's SplitCompat setup.
If Android exposes the installed module's dispatcher in a separate
app-private directory, pass that directory to both
probeLiteRtLmNpuDispatch(dispatchLibDir: directory)andLiteRtLmModelParams(device: ComputeDevice.npu, dispatchLibDir: directory). Use the directory containing the actual library files for one vendor. An APK-backed path containing!/reportsextractionDisabled.
The app handles feature installation and SplitCompat. Resolver tests cover directory selection. On-demand delivery through Google Play remains untested.
Single-vendor builds outside Play#
For a Tensor-only build, add the Google Maven runtime to the app module with
google() in the project's dependency repositories. Keep the base app's
extraction setting and preserve dispatcher bytes there.
dependencies {
implementation("com.google.ai.edge.litert:litert-npu-runtime-google-tensor:2.4.1")
}
A Flutter release APK built this way included the arm64 dispatcher and passed
an NPU turn on Tensor G6. The APK omitted the AAR's LICENSE and
THIRD_PARTY_NOTICE.txt. Review the vendor notices and verify their inclusion
before distributing your app. Use device-targeted delivery if you support
multiple vendors.
Qualcomm (Galaxy S24, SM8650)#
For Gemma3-1B-IT_q4_ekv1280_sm8650.litertlm, pair
com.google.ai.edge.litert:litert-npu-runtime-qualcomm:2.4.1 with
QAIRT 2.52.0.261104. Match QAIRT to the dispatcher version.
Google's linked sample pairing (Maven 2.3.0 and QAIRT 2.50) returned
unsupportedProtocol. Updating Maven alone left a QNN System API mismatch.
Enable extraction in the base app and preserve dispatcher and QAIRT
library bytes in the device-targeted feature modules. Declare Android's
libcdsprpc.so as an optional <uses-native-library> and pass
applicationContext.applicationInfo.nativeLibraryDir as dispatchLibDir.
The smallest tested set that reported participated contained five
Qualcomm-specific libraries (23,814,804 bytes uncompressed):
- Maven:
libLiteRtDispatch_Qualcomm.so. -
QAIRT:
libQnnSystem.so,libQnnHtp.so,libQnnHtpV75Stub.soandlibQnnHtpV75Skel.so.
The test used Android's FastRPC and omitted libQnnHtpPrepare.so and the
Maven compiler plugin. A Galaxy Tab S9 (SM8550, HTP v73) returned
LlamaUnsupportedException with the SM8650 (v75) model. See
Qualcomm tracking.
MediaTek (Galaxy Tab S10+, MT6989)#
For Gemma3-1B-IT_q4_ekv1280_mt6989.litertlm, the tested feature packaged the
com.google.ai.edge.litert:litert-npu-runtime-mediatek:2.4.1 dispatcher
(libLiteRtDispatch_MediaTek.so, 183,200 bytes). Declare the firmware's
libneuronusdk_adapter.mtk.so and libneuron_sys_util.mtk.so
as optional
<uses-native-library> entries and pass the extracted nativeLibraryDir
as dispatchLibDir.
Two fresh processes reported compatible / admitted / participated using
the tablet's firmware libraries. The test did not need an SDK-supplied
adapter. See MediaTek tracking.
Vendor licenses and notices#
llamadart ships no vendor NPU binaries. The app developer supplies them and is responsible for any SDK terms, including the Qualcomm AI Stack License and MediaTek's terms, and for including the applicable notices. This packaging guidance does not constitute legal advice.
Probe before downloading the model#
import 'package:llamadart/llamadart.dart';
Future<bool> canPrepareNpuModel() async {
final report = await probeLiteRtLmNpuDispatch();
if (!report.isAvailable) {
print(report.unsupportedReason);
return false;
}
print('Discovered NPU dispatcher: ${report.vendor?.name}');
return true;
}
The probe checks the installed runtime's placement ABI and finds a single
readable dispatcher. With Google's Tensor dispatcher it returns
unsupportedTensorFirmware on API levels below 36 or on a BP2A
build.
Model compatibility, engine admission, and turn participation require the
actual model and device. The probe returns unsupportedPlatform on Web and
every native ABI except Android arm64.
Store the compiled model#
Import the .litertlm bundle as a regular file under internal app storage
such as Android's Context.filesDir. Verify the SHA-256 of the imported file
and pass its absolute path to ModelSource.path. On the tested Pixel 11 Pro
(Tensor G6), the same verified bundle failed at the driver read from
app-scoped external storage and reported participated from internal
app storage.
Load and verify a turn#
llamadart discovers the extracted directory when you request
ComputeDevice.npu. For custom deployments or tests, you can override the
directory with LiteRtLmModelParams.dispatchLibDir.
import 'package:llamadart/llamadart.dart';
Future<void> runNpuTurn(String modelPath) async {
final engine = LlamaEngine(LlamaBackend());
try {
await engine.setModel(
LlamaModel(ModelSource.path(modelPath)),
params: const LiteRtLmModelParams(
device: ComputeDevice.npu,
contextSize: 4096,
),
);
await for (final chunk in engine.create(
const [
LlamaChatMessage.fromText(
role: LlamaChatRole.user,
text: 'Repeat this exact word: hello.',
),
],
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 after each turn.
| Observation | Meaning |
|---|---|
| Unverified |
The load can be provisional until deferred initialization. A turn of
none
or
pending
has no final placement confirmation.
|
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 an NPU invocation in a successful primary-model send. CPU partition coverage and vision or audio encoder placement remain unknown. |
With turn-progress ABI 1 (bundled since v0.20.0-2), an explicit NPU turn
streams once the runtime observes NPU participation. A runtime without that ABI
holds output until completed-turn verification. Placement ABI 1 still verifies
the final result. If the turn is cancelled or fails after streaming starts,
text already delivered remains visible and unverified buffered text is discarded.
A Dart stopSequences match truncates visible output. Once NPU streaming has
started, native generation continues to EOS or a generation limit so final
placement can be verified. A terminal placement failure still raises
LlamaUnsupportedException. To retry on another device, select
ComputeDevice.cpu or ComputeDevice.gpu and omit dispatchLibDir.
Diagnose a refusal#
A refusal throws LlamaUnsupportedException. With deferred initialization,
this can happen on first use after setModel returns.
| Condition | Diagnostic |
|---|---|
extractionDisabled |
The runtime or override points inside an APK. Enable extraction in the base app and rebuild, or pass a readable directory of extracted libraries. |
missingDispatcher |
The installed app has no readable dispatcher in the selected directory. Check that the vendor split for this device was delivered and extracted. |
multipleDispatchers |
LiteRT loads the first matching library regardless of SoC. Target one vendor runtime per device. An explicit override also requires a single dispatcher. See LiteRT #11250 . |
unresolvableDirectory |
The runtime could not identify or inspect an extracted directory. Check extraction, or pass a known readable single-vendor directory. |
runtimeUnsupported |
Install the pinned runtime or a custom runtime with C API 1 and NPU placement ABI 1. |
| Incompatible model or environment |
Native preflight can report
unsupportedProtocol
or
incompatible
. Check the dispatch interface, driver, SoC and compiled bundle.
|
| Completed turn without participation |
The error names the observed turn state, such as
cpuFallback
or
none
. Held output is discarded. Any text already streamed had positive progress evidence.
|
Device evidence#
On a DDP Pixel 11 Pro (Tensor G6, Android API 37), APKs built with
bundletool --local-testing delivered the Tensor feature. With extraction
enabled, auto-discovery found the dispatcher and the compiled Gemma 4 E2B
model reported compatible / admitted / participated. With extraction
disabled or the feature absent, the probe diagnosed the missing prerequisite
and the forced NPU request refused with no output. See
issue #2549.
The placement qualification observed participation on short text turns with the compiled Tensor G6 model, including after reload and cancellation recovery. Play Console delivery, Play device-group assignment and on-demand splits remain untested. The Qualcomm and MediaTek observations above used local bundletool delivery.
Google Tensor G3, G4 and G5#
Google's Tensor dispatcher requires Android 16 (API 36) or later and
excludes build IDs starting with BP2A. An explicit NPU request on either
unsupported firmware path throws LlamaUnsupportedException before native
engine creation. The tested Android 15 builds on Pixel 9 Pro
(BP1A.250505.005) and Pixel 8 Pro (BP1A.250505.005.B1) also lacked
libedgetpu_litert.so. If an eligible build cannot load its vendor library,
native placement preflight still returns a typed refusal.
With the Tensor 2.4.1 dispatcher, these Android 16 runs reported
compatible / admitted / participated with community Gemma 3 1B builds.
| Device | Firmware | SouthBound | Model bundle |
|---|---|---|---|
| Pixel 9 (G4) | CP1A.260505.005 |
0.14.0 | Gemma3-1B-IT_int4hadamard_aot_ekv4096_G4.litertlm |
| Pixel 9 Pro Fold (G4) | CP1A.260305.018 |
0.14.0 | Gemma3-1B-IT_int4hadamard_aot_ekv4096_G4.litertlm |
| Pixel 8 (G3) | BP4A.260205.001 |
0.11.0 | Gemma3-1B-IT_int4hadamard_aot_ekv4096_G3.litertlm |
Google's Tensor SDK lists G5 and G6 as supported targets. These G3 and G4 configurations fall outside Google's documented support.
With the same dispatcher on Tensor G5 (Android 16):
-
Google's
Gemma3-1B-IT_q8_ekv1280_Google_Tensor_G5.litertlmcrashed in the device'slibedgetpu_litert.soon all three tested firmware builds (BD1A.250702.001,BD3A.251005.003andCP1A.260505.005, with SouthBound 0.8.0, 0.9.0 and 0.14.0 respectively) across Pixel 10, Pixel 10 Pro, Pixel 10 Pro XL and Pixel 10 Pro Fold. Google's LiteRT-LM Android SDK 0.20.0 reproduced the firmware fault on Pixel 10 runningCP1A.260505.005. -
The community
Gemma3-1B-IT_int8_aot_ekv4096_G5.litertlmreportedparticipatedon Pixel 10 and Pixel 10 Pro XL runningCP1A.260505.005(SouthBound 0.14.0). -
Google's
gemma-4-E2B-it_Google_Tensor_G5.litertlmreturned a typed refusal on Pixel 10 Pro XL running that same firmware. The bundle requires graph version 7 and the firmware supports up to version 6.
For the Google Tensor dispatcher, llamadart writes a marker before native
engine creation, including creation triggered by tokenization. It removes
the marker after native creation settles with confirmed placement or a
typed refusal, or when Dart rejects engine settings before native creation.
When a generation request is cancelled during engine creation, the marker
stays until native creation settles. If the process
terminates during creation, the next attempt with the same model,
dispatcher, SoC and firmware throws LlamaUnsupportedException and names
the marker file.
The marker lives under no_backup/llamadart_npu_attempts in the app's
internal data directory by default. If you set LiteRtLmModelParams.cacheDir,
use a persistent app-private directory and keep that directory consistent
across launches. Stop the app before deleting the named .pending file.
To retry explicitly, pass
LiteRtLmModelParams(device: ComputeDevice.npu, retryUnfinishedNpuAttempt: true).
The first attempt and an explicit retry can still hit the native fault.
Treat NPU as opt-in for each verified model and firmware pairing. Keep a CPU-compatible bundle as a fallback. Tensor crash investigation.
Intel OpenVINO on Windows is tracked separately.
Qualcomm Hexagon HTP for GGUF (Android arm64)#
The pinned llamadart-native v1.1.0-6 release publishes an experimental
Qualcomm Hexagon HTP (HTP0) sidecar for Android arm64. Both build-time
hexagon and runtime ComputeDevice.npu are explicit opt-ins.
ComputeDevice.auto excludes HTP. A contract 2 runtime override that lists no
Hexagon sidecar throws NativeHookContractException when hexagon
is selected.
Requirements and packaging#
-
Opt into
hexagon(aliashtp) inhooks.user_defines.llamadart.llamadart_native_backends.platforms.android-arm64:
hooks:
user_defines:
llamadart:
llamadart_native_backends:
platforms:
android-arm64:
backends: [cpu, vulkan, hexagon]
- Declare Android's FastRPC library in
android/app/src/main/AndroidManifest.xml:
<uses-native-library android:name="libcdsprpc.so" android:required="false" />
-
Configure the app's
android/app/build.gradle.ktsto extract both JNI libraries into the same directory and preserve their bytes. The probe verifies both SHA-256 digests before loadinglibggml-hexagon.sofrom besidelibllamadart.so. An absent sidecar beside the extracted primary library reportsLlamaCppHexagonStatus.missingHostModule. APK-backed or unresolved library paths reportLlamaCppHexagonStatus.runtimeUnsupported. Android Gradle Plugin 9.1.0 changed both digests with default stripping. The following settings preserved both digests in the arm64 release APK:
android {
packaging.jniLibs.useLegacyPackaging = true
packaging.jniLibs.keepDebugSymbols += setOf(
"**/libllamadart.so",
"**/libggml-hexagon.so",
)
}
-
The hook caches the verified sidecar under
.dart_tool/llamadart/native_bundles_v2/v1.1.0-6/android-arm64-hexagon/extracted/in the llamadart package directory. It emitslibggml-hexagon.soas a native code asset. Stagehexagon-assets.json,HEXAGON-NOTICES.txtand theassets/hexagon/libggml-htp-v*.soskeletons as app assets. Preserve the manifest, notice and skeleton bytes. The hook verifies those files and checks that the manifest binds the sidecar to the corelibllamadart.so. -
At runtime, extract the skeletons, manifest and notice into a regular,
app-private directory. Place the skeletons directly in that directory
beside the manifest and notice, then pass it as
hexagonAssetsDir. Paths inside an APK (!/) and symlinks are rejected.
Probe and load#
import 'package:llamadart/llamadart.dart';
Future<String> runHexagonGguf(
String modelPath,
String hexagonAssetsDir,
String prompt,
) async {
final probe = await probeLlamaCppHexagon(
hexagonAssetsDir: hexagonAssetsDir,
);
if (!probe.isAvailable) {
throw LlamaUnsupportedException(probe.unsupportedReason ?? 'Unavailable');
}
final engine = LlamaEngine(LlamaBackend());
try {
await engine.setModel(
LlamaModel(ModelSource.path(modelPath)),
params: LlamaCppModelParams(
device: ComputeDevice.npu,
hexagonAssetsDir: hexagonAssetsDir,
),
);
return await engine.generate(prompt).join();
} finally {
await engine.dispose();
}
}
LlamaCppModelParams(device: ComputeDevice.npu, hexagonAssetsDir: ...) verifies libllamadart.so
admission/barriers, libggml-hexagon.so, libcdsprpc.so, skeleton digests, and
owner_build_identity, configures ADSP_LIBRARY_PATH and GGML_HEXAGON_LIBHTP_DIR
once per process before loading libggml-hexagon.so, and routes single-device inference exclusively to
HTP0 (LlamaLoadReport.device == ComputeDevice.npu, backendName == 'Hexagon (HTP0)'). Once a process initializes Hexagon for a directory, switching to another directory returns
LlamaCppHexagonStatus.reinitializationRequired.
Hexagon device evidence#
A Flutter 3.47.1 arm64 release APK ran Qwen3-0.6B Q4_0 through the public
LlamaEngine with the published llamadart-native v1.1.0-6 core and sidecar.
The first successful device run measured three generations per backend, with
two CPU threads, a 58-token prompt, and prompt-prefix reuse disabled.
Throughput is the median native prefill and decode rate in tokens per second.
Load time is the first model load in each process and excludes the explicit
model-free HTP probe.
| Device | CPU / HTP0 prefill | CPU / HTP0 decode | CPU / HTP0 model load |
|---|---|---|---|
| Galaxy S24, SM8650/v75, Android 14 | 234 / 2,105 | 75 / 104 | 810 / 449 ms |
| Galaxy S25 Ultra, SM8750/v79, Android 15 | 382 / 2,773 | 112 / 126 | 548 / 344 ms |
Both phones completed repeated load/generate/dispose cycles and resumed
generation after stream cancellation. FastRPC opened the matching unsigned
skeleton in CDSP domain 3 on each phone. llama.cpp placed 29 of 29 model layers
on HTP0, and profiling recorded 97 DSP batches on the S24 and 94 on the S25
Ultra with nonzero operations and cycles. After HTP0 registration, GPU enumeration
excluded HTP0, ComputeDevice.auto selected CPU, and an explicit GPU request
was refused by the Qualcomm Vulkan driver guard. A Tensor G4 Pixel 9 Pro and
an otherwise identical Galaxy APK without the FastRPC manifest declaration
returned missingFastRpc and rejected an explicit NPU load with
LlamaUnsupportedException. Missing and tampered skeletons, a second skeleton
directory, and an intentionally unavailable v99 skeleton also failed closed.
Await engine.dispose() before shutting down and let Android handle process
lifecycle. Forcing C exit(0) from the Flutter app produced signals during
HTP generation on both phones and after completed or disposed HTP sessions on
the S25 Ultra. CPU and no-runtime exit controls also produced signals. The
completed-session Hexagon GGML_ABORT path did not reproduce. DSP stop or
queue-close errors can still take that path. Hexagon HTP remains experimental,
with inference evidence for this Q4_0 model on the two tested SoCs. Follow the teardown work
in #2553.
Studio internals#
The standalone Studio APK bundles the verified Tensor Maven
dispatcher and notices. Studio's opt-in arm64 app bundle puts the Tensor G6
and MediaTek MT6989 kits in separate conditional install-time features.
Studio matches the device SoC and verified dispatcher to the vendor and
directory returned by probeLiteRtLmNpuDispatch() before enabling NPU.
Model Hub recommends the pinned Gemma 4 E2B bundle on Tensor G6. On a verified
MT6989 host, Import MT6989 model opens the local model picker workflow.
Studio verifies the pinned Gemma 3 1B file's SHA-256 before loading it.
The Studio Play internal-track check remains open in issue #2549.
Studio's arm64 base packages the llama.cpp Hexagon sidecar and extracts its
DSP assets before calling probeLlamaCppHexagon(). The Hexagon and LiteRT-LM
probes run independently. Model Hub recommends Qwen3 0.6B (Q4_0) when
the Hexagon probe succeeds. For a loaded GGUF, use the Inspector's NPU
compute target and Apply & Reload. Check NPU · Hexagon (HTP0)
under
Applied configuration. Hexagon notices opens the packaged attribution
from the sidebar or Inspector. The device evidence
above describes the tested release harness. Studio device qualification is a
separate step.