Skip to content

Expose engineId on native plugin bindings/registrars (FlutterPluginBinding, FlutterPluginRegistrar) for FFI/JNI plugins #195876

Description

@tarrinneal

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, and FlutterPluginBinding holds a private final FlutterEngine flutterEngine field, but FlutterPluginBinding.getFlutterEngine() is @Deprecated and FlutterPluginBinding does not have a getEngineId() method.
    • FlutterEngine.engineForId(long) is also marked @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE).
  • iOS / macOS (FlutterPluginRegistrar):
    • FlutterEngine.engineIdentifier and +[FlutterEngine engineForIdentifier:] exist in FlutterEngine_Internal.h, which is not part of the public headers available to plugins, and FlutterPluginRegistrar does not expose engineIdentifier.
  • Linux / Windows (FlPluginRegistrar / FlutterDesktopPluginRegistrarRef):
    • fl_engine_for_id and FlutterDesktopEngineForId are 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:

  1. Android (FlutterPlugin.FlutterPluginBinding): Add public long getEngineId() { return flutterEngine.getEngineId(); }.
  2. iOS / macOS (FlutterPluginRegistrar): Expose engineIdentifier (int64_t) on FlutterPluginRegistrar.
  3. Linux / Windows (FlPluginRegistrar / FlutterDesktopPluginRegistrarRef): Expose the engine ID on the respective plugin registrar APIs.

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: proposalA detailed proposal for a change to Flutter
    engineflutter/engine related. See also e: labels.
    e: embedderUsers of the Embedder API
    and removed
    in triagePresently being triaged by the triage team
    on Nov 3, 2026
  2. puneetkukreja98 commented on Nov 3, 2026

    @puneetkukreja98
    Contributor

    @tarrinneal Thanks for the proposal, routing this to team-engine for further investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: API breakBackwards-incompatible API changesc: proposalA detailed proposal for a change to Fluttere: embedderUsers of the Embedder APIengineflutter/engine related. See also e: labels.team-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions