Repository navigation
Description
Use case
In #163476 (for #163430), PlatformDispatcher.instance.engineId was added on the Dart side along with engine-level ID tracking on the native side so FFI/JNI plugins can associate Dart isolates with their corresponding native FlutterEngine.
However, native plugins only receive a FlutterPluginBinding (Android) or FlutterPluginRegistrar (iOS/macOS/Linux/Windows) during registration/detachment, and none of the public plugin binding/registrar APIs currently expose the engine ID:
- Android (
FlutterPlugin.FlutterPluginBinding):FlutterEngine.getEngineId()is public, andFlutterPluginBindingholds aprivate final FlutterEngine flutterEnginefield, butFlutterPluginBinding.getFlutterEngine()is@DeprecatedandFlutterPluginBindingdoes not have agetEngineId()method.FlutterEngine.engineForId(long)is also marked@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE).
- iOS / macOS (
FlutterPluginRegistrar):FlutterEngine.engineIdentifierand+[FlutterEngine engineForIdentifier:]exist inFlutterEngine_Internal.h, which is not part of the public headers available to plugins, andFlutterPluginRegistrardoes not exposeengineIdentifier.
- Linux / Windows (
FlPluginRegistrar/FlutterDesktopPluginRegistrarRef):fl_engine_for_idandFlutterDesktopEngineForIdare internal-only (fl_engine_private.h/flutter_windows_internal.h), and the plugin registrars do not expose an engine ID getter.
Because plugins using JNI/FFI (such as plugins generated with Pigeon's native interop support) register directly in native memory rather than on a per-engine BinaryMessenger, they currently have no non-deprecated public way during onAttachedToEngine / onDetachedFromEngine (or registerWithRegistrar:) to scope their registered host API instances to a specific engine. When multiple FlutterEngine instances run in the same process (e.g., background FlutterEngines alongside the main UI engine), one engine attaching or detaching can overwrite or unregister another engine's JNI/FFI host API instance (see #194920 and flutter/packages#13359).
Proposal
Expose the engine ID publicly on the native plugin binding/registrar interfaces so FFI/JNI plugins and code generators (like Pigeon) can key per-engine native registrations by engineId without calling @Deprecated or internal engine APIs:
- Android (
FlutterPlugin.FlutterPluginBinding): Addpublic long getEngineId() { return flutterEngine.getEngineId(); }. - iOS / macOS (
FlutterPluginRegistrar): ExposeengineIdentifier(int64_t) onFlutterPluginRegistrar. - Linux / Windows (
FlPluginRegistrar/FlutterDesktopPluginRegistrarRef): Expose the engine ID on the respective plugin registrar APIs.
Activity
puneetkukreja98 commentedon Nov 3, 2026
@tarrinneal Thanks for the proposal, routing this to team-engine for further investigation.
Expose engineId on native plugin bindings and registrars on Android, …
[beta] Expose engineId on native plugin bindings and registrars on An…