Repository: flutter
Issue: ☂️ Native assets support
Labels: c: new feature,tool,c: proposal,P2,team-tool,triaged-tool

**Native assets support in Flutter MacOS, iOS, Linux, and Windows is available on the master channel behind an experimental flag: `flutter config --enable-native-assets` and `flutter create --template=package_ffi [package name]`.**

A high level tracking issue for supporting native assets.

Native assets enables packages to specify a top-level `build.dart` that is invoked by launchers (dartdev and flutter_tools) to build/download native libraries and communicate back which native libraries need to be bundled and under which "asset id".

From a Flutter context, the native assets feature will enable testing native code with `flutter test`, which the FFI plugins do not support. From a Dart+Flutter context packages will be compatible with both Dart and Flutter, removing the need for publishing two versions on pub (one for Dart and one for Flutter).

More details can be found in:

* https://github.com/dart-lang/sdk/issues/50565

Dart standalone support has landed behind an experimental flag (`dart  --enable-experiment=native-assets`).

This issue tracks implementing native assets in flutter tools

* [x] MacOS
* [x] iOS
   * [x] https://github.com/flutter/flutter/issues/140544
* [x] Linux
* [x] Android
   * [x] Flutter app
   * [x] Add2app
* [x] Windows

Use cases that should be supported

* `flutter run`
    * debug
       * hot reload (1)
       * hot restart (1)
    * release/profile
* `flutter build` debug/release/profile
* `flutter test` / `dart test`
*  add-2-app (e.g. `flutter build macos-framework` for MacOS)
* `flutter run -dflutter-tester`

Test coverage will be through end-to-end integration tests that exercise the dynamic libraries provided by packages.

Landing plan is to land this behind an experimental flag on the main branch only. This has the following benefits:

* Support for the various OSes can be in separate CLs, simplifying code review.
* We defer settling on the actual `build.dart` protocol until before we get it out of experimental. Users should _not_ publish packages on pub.dev while this feature is in experimental phase.
* Making this available in experimental enables users to give this feature a spin without having to build their own version of Dart or Flutter. Getting their feedback is important to us to get this feature right.

Please feel free to note additional use cases that we have missed or ask questions on this issue.

Foot notes:

1. This does _not_ bundle new native libraries, but the already bundled native libraries should be accessible.

References:

* Example package with native assets: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli/example/
* Dart tracking issue: https://github.com/dart-lang/sdk/issues/50565

cc @stuartmorgan @vashworth 

Ongoing work related to native assets, build.dart and link.dart hooks:

* [ ] https://github.com/flutter/flutter/issues/140966
   * [ ] https://github.com/flutter/flutter/issues/147186
* [x] https://github.com/flutter/flutter/issues/146263
* [ ] https://github.com/flutter/flutter/issues/146264
* [ ] https://github.com/flutter/flutter/issues/146265
* [x] https://github.com/flutter/flutter/issues/146270
   * [x] https://github.com/flutter/flutter/issues/147643
* [ ] https://github.com/flutter/flutter/issues/147544
* [ ] https://github.com/flutter/flutter/issues/142933
* [x] https://github.com/flutter/flutter/issues/148044
* [x] https://github.com/flutter/flutter/issues/148051
* [ ] https://github.com/flutter/flutter/issues/151890
* [ ] https://github.com/flutter/flutter/issues/154425
* [ ] https://github.com/flutter/flutter/issues/151646