[pigeon] Add FFI and JNI support to Swift and Kotlin (#11352) This PR introduces optional Native Interop to Pigeon, enabling direct communication between Dart and native code without the overhead of traditional MethodChannel serialization. It leverages FFI (Foreign Function Interface) for Swift (iOS/macOS) and JNI (Java Native Interface) for Kotlin (Android). This represents a significant architectural shift, moving from message-based passing to direct memory sharing and function calls. It also updates the concurrency model for asynchronous methods, moving from completion handlers/callbacks to modern language features: async/await in Swift and Coroutines in Kotlin. Generators Covered Swift Generator: Updated to support FFI bindings and async/await for asynchronous methods. Kotlin Generator: Updated to support JNI bindings and Kotlin Coroutines for asynchronous methods. Dart Generator: Updated to handle the generated interop bindings on the Dart side. What's In Scope 1. Infrastructure: Added core support for useFfi and useJni options. 2. Automation: Implemented multi-step generation flows that automatically invoke jnigen and ffigen to produce final bindings. 3. Config Generation: Added jnigen_config_generator.dart and ffigen_config_generator.dart to generate the necessary configuration files for the external tools. 4. Documentation: Added a detailed native_interop_guide.md explaining prerequisites, setup, and usage. Tests: Added ni_tests.dart and associated generated files and integration tests to verify the feature. What's Out of Scope 1. Other Languages: This PR specifically targets Swift and Kotlin for the Native Interop feature. Support for Objective-C, C++, and GObject is not included in this interop implementation, and may not be in the future. 2. Performance Optimization for Complex Classes: As noted in the guide, there is a known performance regression when transferring complex classes with many fields compared to MethodChannel Pigeon. This PR delivers the functional infrastructure, but optimizing this specific case is left for follow-up work. 3. Non-instant released data. Currently all data that is sent over host or flutter api surfaces is converted to the correct shape and type for the language it is moving toward and the data created in the other language is then discarded. This presents some inefficiencies and potential workflows that are not yet available. work toward https://github.com/flutter/flutter/issues/182230 design doc https://github.com/flutter/flutter/issues/181430
This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages directory to see all packages.
These packages are also available on pub.
Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.
If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.
If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.
These are the packages hosted in this repository: