Native assets support for Android (#135148)
Support for FFI calls with `@Native external` functions through Native assets on Android. 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. Mainly follows the design of the previous PRs. For Android, we detect the compilers inside the NDK inside SDK. And bundling of the assets is done by the flutter.groovy file. The `minSdkVersion` is propagated from the flutter.groovy file as well. The NDK is not part of `flutter doctor`, and users can omit it if no native assets have to be build. However, if any native assets must be built, flutter throws a tool exit if the NDK is not installed. Add 2 app is not part of this PR yet, instead `flutter build aar` will tool exit if there are any native assets.
This commit is contained in:
@@ -339,6 +339,8 @@ Future<int> exec(
|
||||
Map<String, String>? environment,
|
||||
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
|
||||
String? workingDirectory,
|
||||
StringBuffer? output, // if not null, the stdout will be written here
|
||||
StringBuffer? stderr, // if not null, the stderr will be written here
|
||||
}) async {
|
||||
return _execute(
|
||||
executable,
|
||||
@@ -346,6 +348,8 @@ Future<int> exec(
|
||||
environment: environment,
|
||||
canFail : canFail,
|
||||
workingDirectory: workingDirectory,
|
||||
output: output,
|
||||
stderr: stderr,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -898,3 +902,30 @@ Future<T> retry<T>(
|
||||
await Future<void>.delayed(delayDuration);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createFfiPackage(String name, Directory parent) async {
|
||||
await inDirectory(parent, () async {
|
||||
await flutter(
|
||||
'create',
|
||||
options: <String>[
|
||||
'--no-pub',
|
||||
'--org',
|
||||
'io.flutter.devicelab',
|
||||
'--template=package_ffi',
|
||||
name,
|
||||
],
|
||||
);
|
||||
await _pinDependencies(
|
||||
File(path.join(parent.path, name, 'pubspec.yaml')),
|
||||
);
|
||||
await _pinDependencies(
|
||||
File(path.join(parent.path, name, 'example', 'pubspec.yaml')),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _pinDependencies(File pubspecFile) async {
|
||||
final String oldPubspec = await pubspecFile.readAsString();
|
||||
final String newPubspec = oldPubspec.replaceAll(': ^', ': ');
|
||||
await pubspecFile.writeAsString(newPubspec);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user