Native assets support for Android Add2app (#140802)

Support for FFI calls with @Native external functions through Native assets on Android add to app. This enables bundling native code without any build-system boilerplate code.

For more info see:

*  https://github.com/flutter/flutter/issues/129757

## Implementation details for Android add2app

The `.so` files are bundled with the same mechanism that bundles `libapp.so`.
This commit is contained in:
Daco Harkes
2024-01-09 09:47:53 +01:00
committed by GitHub
parent 29db9dbd44
commit b2ef2802d2
6 changed files with 52 additions and 114 deletions

View File

@@ -78,7 +78,6 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
Uri? yamlParentDirectory,
required FileSystem fileSystem,
required int targetAndroidNdkApi,
bool isAndroidLibrary = false,
}) async {
const OS targetOS = OS.android;
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, targetOS);
@@ -115,9 +114,6 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
}
ensureNoLinkModeStatic(nativeAssets);
globals.logger.printTrace('Building native assets for $targets done.');
if (isAndroidLibrary && nativeAssets.isNotEmpty) {
throwToolExit('Native assets are not yet supported in Android add2app.');
}
final Map<Asset, Asset> assetTargetLocations =
_assetTargetLocations(nativeAssets);
await _copyNativeAssetsAndroid(buildUri_, assetTargetLocations, fileSystem);

View File

@@ -932,13 +932,6 @@ const String kDarwinArchs = 'DarwinArchs';
/// This is expected to be a space-delimited list of architectures.
const String kAndroidArchs = 'AndroidArchs';
/// If the current build is `flutter build aar`.
///
/// This is expected to be a boolean.
///
/// If not provided, defaults to false.
const String kIsAndroidLibrary = 'IsAndroidLibrary';
/// The define to control what min Android SDK version is built for.
///
/// This is expected to be int.

View File

@@ -306,8 +306,6 @@ class NativeAssets extends Target {
Uri projectUri,
FileSystem fileSystem,
NativeAssetsBuildRunner buildRunner) {
final bool isAndroidLibrary =
environment.defines[kIsAndroidLibrary] == 'true';
final String? androidArchsEnvironment = environment.defines[kAndroidArchs];
final List<AndroidArch> androidArchs = _androidArchs(
targetPlatform,
@@ -323,7 +321,6 @@ class NativeAssets extends Target {
buildRunner: buildRunner,
androidArchs: androidArchs,
targetAndroidNdkApi: targetAndroidNdkApi,
isAndroidLibrary: isAndroidLibrary,
);
}