Skip to content

☂️ Build hooks & Code assets #129757

Description

@dcharkes

Build hooks and code assets support in Flutter is available in stable since 3.38 and Dart 3.10: flutter create --template=package_ffi [package name].

Ongoing work for tree-shaking and other features related to hooks can be tracked in: Native Assets

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:

Current ongoing work can be tracked in: Native Assets

Dart standalone support has landed behind an experimental flag (dart --enable-experiment=native-assets).

This issue tracks implementing native assets in flutter tools

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:

cc @stuartmorgan @vashworth

Ongoing work related to native assets, build.dart and link.dart hooks:

Activity

  1. self-assigned this
    on Jun 29, 2023
  2. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    toolAffects the "flutter" command-line tool. See also t: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Jun 29, 2023
  3. 38 remaining items

  4. added
    tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.
    on Jul 11, 2025
  5. gaaclarke commented on Jul 14, 2025

    @gaaclarke
    Member

    In #112727 I proposed adding similar functionality to the flutter tool, one of the use cases was to provide support for rust plugins. I was imagining calling cargo at the appropriate time and linking the generated library to the final flutter binary. Then we could call into it with a c interface. This sounds like it could handle that case at a better layer.

  6. knopp commented on Jul 14, 2025

    @knopp
    Member

    @gaaclarke, there is already native_toolchain_rust that does that for native assets / hooks, it's just really out of date and I need to find time to update it as there have been many, many, many breaking changes meanwhile :)

  7. maks commented on Jul 14, 2025

    @maks
    Contributor

    Sorry if I got the wrong end of the stick but @gaaclarke is what you are suggesting covered by #47718 ? or would libs into a Flutter exe be different to what is required for a standalong Dart exe ?

  8. gaaclarke commented on Jul 14, 2025

    @gaaclarke
    Member

    Sorry if I got the wrong end of the stick but @gaaclarke is what you are suggesting covered by #47718 ? or would libs into a Flutter exe be different to what is required for a standalong Dart exe ?

    I didn't really specify, I was just talking generally. If a rust target created a static library I would expect it to be linked statically, which would make what happens between dart and flutter very similar. That's what's covered in that issue. Dynamic libraries are a bit more complex for flutter versus dart because each target platform (iOS, Android) has different preferences about where it wants to find dynamic libraries, has different tools/file formats, etc. I haven't been following Daco's work but I'm sure he's been considering that.

  9. dcharkes commented on Jul 15, 2025

    @dcharkes
    ContributorAuthor

    Sorry if I got the wrong end of the stick but @gaaclarke is what you are suggesting covered by #47718 ? or would libs into a Flutter exe be different to what is required for a standalong Dart exe ?

    I didn't really specify, I was just talking generally. If a rust target created a static library I would expect it to be linked statically, which would make what happens between dart and flutter very similar. That's what's covered in that issue. Dynamic libraries are a bit more complex for flutter versus dart because each target platform (iOS, Android) has different preferences about where it wants to find dynamic libraries, has different tools/file formats, etc. I haven't been following Daco's work but I'm sure he's been considering that.

    Yes, the code assets support in Flutter (and Dart) takes care to rewrite dynamic loading paths, code signing, etc.

    Static linking against the AOT-compiled Dart code is actually more tricky, as the Dart code is not output in the native format for each OS currently. With the work on link hooks (dart-lang/native#153) we'd already get tree-shaking of native code based on what Dart code is tree-shaken. So, static linking would only remove the dynamic linker call and make FFI calls static calls into the C code, but at considerable engineering effort. Therefore, we're focussing on dynamic libraries for now and we're not working actively on dart-lang/sdk#47718, dart-lang/sdk#49418 , and https://dart-review.googlesource.com/c/sdk/+/251263.

  10. loic-sharma commented on Aug 11, 2025

    @loic-sharma
    Member

    In older versions it's available behind an experimental flag on the master channel: flutter config --enable-native-assets.

    @dcharkes Just to confirm, does this the flutter config --enable-native-assets option does nothing on the latest stable? Should we deprecate/remove this option from the Flutter tool?

  11. dcharkes commented on Aug 12, 2025

    @dcharkes
    ContributorAuthor

    In older versions it's available behind an experimental flag on the master channel: flutter config --enable-native-assets.

    @dcharkes Just to confirm, does this the flutter config --enable-native-assets option does nothing on the latest stable? Should we deprecate/remove this option from the Flutter tool?

    The experiment is not enable-able on stable, and is on by default and disable-able on beta and master. So the experiment still serves a purpose. Once we also enable it on stable, we can remove it.

  12. CodeDoctorDE commented on Nov 12, 2025

    @CodeDoctorDE
    Contributor
  13. dcharkes commented on Nov 13, 2025

    @dcharkes
    ContributorAuthor

    Yes, build hooks and code assets support in Flutter is available in stable since 3.38 and Dart 3.10: flutter create --template=package_ffi [package name].

    Ongoing work for tree-shaking and other features related to hooks can be tracked in: Native Assets

  14. github-actions commented on Nov 28, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterdependency: dartDart team may need to help usr: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions