prepareAndroidNpuDispatchDir function
- List<
String> libs, - NpuStack vendor,
- NpuPlatform platform
Returns the directory to hand LiteRT as dispatch_lib_dir on Android for
one vendor's stack, libs (CodeAsset names) — for the LLM engine and the
EmbeddingGemma 2 embedding pass alike (the pass asks from
LiteRtEmbeddingBackend.describe(), on the caller's isolate: this goes
through a platform channel, which core's worker cannot reach).
LiteRT scans it for every libLiteRtDispatch*.so and loads the first it
finds, so the directory must hold this vendor's dispatch and no other's.
What else must be there is the vendor's rule: Qualcomm's dispatch loads
libQnnHtp/libQnnSystem from it and puts it on ADSP_LIBRARY_PATH for the
Skels, so the whole QNN stack must exist there as files. The core plugin
returns a directory holding exactly libs — nativeLibraryDir when the
installer extracted them and it holds no other dispatch or compiler plugin,
else a copy taken from the base APK or its config split (a Play install).
A core from before that rule returns nativeLibraryDir whatever else it
holds, so the release that adds a second Android vendor must raise this
package's flutter_edge_ai floor to the first core with it. The list comes
from here because the build decides it; platform asks the core plugin
(FlutterNpuPlatform.prepareAndroidDispatchDir).
Implementation
Future<String> prepareAndroidNpuDispatchDir(
List<String> libs,
NpuStack vendor,
NpuPlatform platform,
) async {
final dir = await platform.prepareAndroidDispatchDir([
for (final n in libs) androidLibFileName(n),
], vendor);
if (dir == null) {
throw const NpuDispatchUnavailableException(
'prepareNpuDispatchDir returned no directory',
);
}
return dir;
}