bundleFamilyRuntime function
Future<void>
bundleFamilyRuntime(
- BuildInput input,
- BuildOutputBuilder output, {
- required String family,
Bundles family's library for the hook's target under
familyRuntimeAssetName, in the calling family's package: Google's
per-family library (familyRuntimes).
Implementation
Future<void> bundleFamilyRuntime(
BuildInput input,
BuildOutputBuilder output, {
required String family,
}) async {
final code = input.config.code;
requireDynamicLinking(code);
final target = buildTarget(code);
final runtime = requireFamilyRuntime(family, target);
if (code.targetOS == OS.android &&
code.android.targetNdkApi < familyRuntimeMinimumAndroidApi) {
throw UnsupportedError(
"mediapipe_$family runs Google's MediaPipe library, which needs Android "
'9 (API $familyRuntimeMinimumAndroidApi); this app targets API '
'${code.android.targetNdkApi}. Set minSdk = '
'$familyRuntimeMinimumAndroidApi in android/app/build.gradle(.kts).',
);
}
final source = hookAssetSource(input);
final cache = Directory.fromUri(
input.outputDirectoryShared.resolve('${runtime.sha256}/'),
);
final download = await downloadVerified(
runtime.asset,
File.fromUri(cache.uri.resolve(runtime.fileName)),
source: source,
);
if (await download.length() != runtime.bytes) {
throw StateError('$target $family runtime size mismatch.');
}
final library = code.targetOS == OS.iOS
? await _extractIosBinary(
download,
simulator: code.iOS.targetSdk == IOSSdk.iPhoneSimulator,
)
: download;
output.dependencies.add(download.uri);
output.assets.code.add(
CodeAsset(
package: input.packageName,
name: familyRuntimeAssetName,
linkMode: DynamicLoadingBundled(),
file: library.uri,
),
);
}