Skip to content

io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative - Google Play Store crashes #174859

Open

Description

@JonasJW

Steps to reproduce

I'm getting io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative after upgrading Flutter from 3.27.x. On 3.27.x I don't get these crashes

Expected results

No crashes in Play Console

Actual results

Getting crash reports in Play Console with the following stacktrace:

Exception java.lang.RuntimeException: Cannot execute operation because FlutterJNI is not attached to native.
  at io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative (FlutterJNI.java:512)
  at io.flutter.embedding.engine.FlutterJNI.scheduleFrame (FlutterJNI.java:965)
  at io.flutter.embedding.engine.renderer.FlutterRenderer.scheduleEngineFrame (FlutterRenderer.java:1299)
  at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer.onImage (FlutterRenderer.java:621)
  at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer$PerImageReader.lambda$new$0 (FlutterRenderer.java:505)
  at android.media.ImageReader$1.run (ImageReader.java:916)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8762)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:604)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)

Code sample

Unfortunately, I have no idea what causes this and only have an app in production that produces the issue, which can't be made public

Screenshots or Video

Image

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.35.2, on macOS 15.3.1 24D70 darwin-arm64, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 16.2)
    ! CocoaPods 1.15.2 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
[✓] Chrome - develop for the web
[✓] Android Studio (version 2025.1)
[✓] VS Code (version 1.100.0)
[✓] Connected device (4 available)
[✓] Network resources

! Doctor found issues in 1 category.

Activity

  1. darshankawar commented on Sep 3, 2025

    @darshankawar
    Member

    @JonasJW
    Are you using platform-views in your code, for ex: useAndroidViewSurface ? If so, we would need to know the platform view mode being used, Virtual Display, Hybrid Composition, or Texture Layer Hybrid Composition.
    Can you also provide your app's pubspec.yaml to know the dependencies you are using ?
    Can you also provide the entire stacktrace or is that the only one you get ?
    maybe related to #168716 but it doesn't have the FlutterJNI related traces.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 3, 2025
  3. JonasJW commented on Sep 3, 2025

    @JonasJW
    Author

    @darshankawar thanks for the quick reply!

    No, I'm not using platform views.

    These are the packages I use:

    dependencies:
      flutter:
        sdk: flutter
      flutter_localizations:
        sdk: flutter
      firebase_core: ^3.13.0
      firebase_auth: ^5.5.3
      cloud_firestore: ^5.6.7
      cloud_functions: ^5.5.0
      firebase_storage: ^12.4.7
      firebase_analytics: ^11.4.5
      firebase_analytics_web: ^0.5.10+11
      firebase_crashlytics: ^4.3.5
      google_sign_in: ^6.1.0
      google_sign_in_web: ^0.12.0
      sign_in_with_apple: ^6.1.3
      crypto: ^3.0.1
      flutter_native_splash:
      cupertino_icons: ^1.0.2
      shared_preferences: ^2.0.15
      provider: ^6.0.3
      logger: ^2.0.2+1
      auto_size_text: ^3.0.0-nullsafety.0
      flutter_svg: ^2.0.10
      url_launcher: ^6.0.6
      rxdart: ^0.27.1
      audioplayers: ^6.4.0
      flutter_tts: ^4.2.3
      wakelock_plus: ^1.2.11
      keyboard_actions: ^4.2.0
      responsive_builder: ^0.7.0
      flutter_form_builder: ^10.0.1
      form_builder_validators: ^11.0.0
      intl: ^0.20.2
      camera: ^0.10.0+4
      path_provider: ^2.0.11
      chewie: ^1.11.3
      keyboard_attachable:depricated
        git:
          url: https://github.com/ryanaidilp/keyboard_attachable.git
          ref: master
      video_player: ^2.9.5
      video_player_web_hls: ^1.3.0
      video_player_media_kit: ^1.0.5
      media_kit_libs_android_video: any
      better_player_enhanced: ^0.0.5
      cached_network_image: ^3.1.0
      image_picker: ^1.0.7
      image_picker_web: any
      image_picker_macos: 0.2.1+1 
      video_compress: ^3.1.4
      flutter_speed_dial: ^7.0.0
      markdown_editable_textinput: ^2.0.2
      flutter_markdown: ^0.7.3+1
      purchases_flutter: ^8.7.4 
      uuid: ^3.0.6
      clock: ^1.1.0
      graphview: ^1.2.0
      font_awesome_flutter: ^10.1.0
      transparent_image: ^2.0.0
      string_similarity: ^2.0.0
      connectivity_plus: ^5.0.0
      visibility_detector: ^0.4.0+2
      in_app_review: ^2.0.8
      universal_html: ^2.2.2
      csslib: ^0.17.3
      scrollable_positioned_list: ^0.3.8
      expandable_page_view: ^1.0.17
      reorderables: ^0.6.0
      transparent_pointer: ^1.0.0
      http: ^1.1.0
      video_thumbnail: ^0.5.3
      photo_view: ^0.14.0
      infinite_scroll_pagination: ^4.0.0
      autoscale_tabbarview: ^1.0.2
      flutter_slidable: ^3.1.1
      expandable_text: ^2.3.0
      mixpanel_flutter: ^2.4.1
      flutter_local_notifications: ^19.4.0
      fwfh_text_style: ^2.23.8 
      fl_chart: ^0.71.0
      skeletonizer: ^2.0.1
      gal: ^2.3.1
      selector_wheel: ^1.1.2
      algolia_helper_flutter: ^1.2.0
      auto_route: ^10.0.1
      health: ^12.1.0
      flutter_timezone: 3.0.1 
      slang: ^4.7.1
      slang_flutter: ^4.7.0
      google_fonts: ^6.2.1
      share_plus: ^10.1.4
      watch_connectivity: ^0.2.1+1
      touchable: ^1.0.2
      sentry_flutter: ^8.14.2
      sentry_logging: ^8.14.2
      logging: ^1.3.0
    

    That is indeed the entire stacktrace I got from Google Play Store.

    I have also noticed this version had Impeller disabled. I just published another version with Impeller enabled to see if the crashes still persist.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 3, 2025
  5. darshankawar commented on Sep 4, 2025

    @darshankawar
    Member

    Thanks for the update. Keeping the issue open for team's tracking.

  6. added
    a: productionIssues experienced in live production apps
    c: crashStack traces logged to the console
    platform-androidAndroid applications specifically
    needs repro infoAutomated crash report whose cause isn't yet known
    team-androidOwned by Android platform team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 4, 2025
  7. stan-at-work commented on Sep 4, 2025

    @stan-at-work

    Same here, built an AAB, uploaded it to the store, and the app crashes.

  8. JonasJW commented on Sep 5, 2025

    @JonasJW
    Author

    Looks like I get this crash with Impeller enabled as well

  9. stan-at-work commented on Sep 5, 2025

    @stan-at-work

    The issue in my case is fixed.

    We used a package called open_file and when i removed that my app runs in release mode

  10. 6 remaining items

  11. Mairramer commented on Oct 16, 2025

    @Mairramer
    Contributor

    I've been encountering this issue with some user as well. Although it occurs sporadically, it is still inconvenient. The main point is that similar errors have existed for many years, yet the stack trace provides no useful information.

  12. Mairramer commented on Oct 17, 2025

    @Mairramer
    Contributor

    As @stan-at-work pointed out, this issue appears to be related to external plugins. I was able to reproduce this error only once, so I’m not entirely sure if that was the cause. The screen was blank for a long time before the application finally started. In my case, it seems to have been triggered by the flutter_background_geolocation plugin.

    I performed a simple check, and on a single occasion it seems that the reference had changed.

    Image Image
  13. sooxt98 commented on Oct 27, 2025

    @sooxt98

    same issue here

    Image
    Exception java.lang.RuntimeException: Cannot execute operation because FlutterJNI is not attached to native.
      at io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative (SourceFile:10)
      at io.flutter.embedding.engine.FlutterJNI.scheduleFrame (SourceFile:4)
      at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer.onImage (SourceFile:57)
      at io.flutter.embedding.engine.renderer.e.onImageAvailable (SourceFile:48)
      at android.media.ImageReader$1.run (ImageReader.java:947)
      at android.os.Handler.handleCallback (Handler.java:958)
      at android.os.Handler.dispatchMessage (Handler.java:99)
      at android.os.Looper.loopOnce (Looper.java:243)
      at android.os.Looper.loop (Looper.java:338)
      at android.app.ActivityThread.main (ActivityThread.java:8470)
      at java.lang.reflect.Method.invoke
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:600)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1064)
    
    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, 3.35.6, on Microsoft Windows [Version 10.0.26100.6584], locale en-US)
    [√] Windows Version (11 Pro 64-bit, 24H2, 2009)
    [!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
        ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
    [√] Chrome - develop for the web
    [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.3)
    [√] Android Studio (version 2022.3)
    [√] VS Code (version 1.105.1)
    [√] VS Code (version 1.91.0-insider)
    [√] Connected device (3 available)
    [√] Network resources
    
    ! Doctor found issues in 1 category.
    
  14. Jezzvega commented on Nov 10, 2025

    @Jezzvega

    Same here, Im getting tens of errors from Android 10 to 15 on Xiaomi, Samsung, Oppo, etc.

    Is there a stable version to downgrade while this gets solved?

    @JonasJW mention 3.27.x do you mean 3.26 should be stable?

    [edit]
    @JonasJW we are using purchases_flutter my errors started after this package was added.

  15. Jezzvega commented on Nov 11, 2025

    @Jezzvega

    @JonasJW hey i just found this #81830

    Makes sense because to implement purchases_ui_flutter you have to replace FlutterActivity with FlutterFragmentActivity.

  16. JonasJW commented on Nov 11, 2025

    @JonasJW
    Author

    It appears that I have finally resolved the issue in my case. I was using video_player_media_kit for Android videos (this fixed a crash with the video_player package a while ago, but the issue doesn't occur at this time anymore). After removing the package altogether I haven't had the crash in the Play Console.

  17. JonasJW commented on Nov 11, 2025

    @JonasJW
    Author

    @Jezzvega I'm using purchases_flutter but not purchases_ui_flutter currently

  18. sooxt98 commented on Nov 13, 2025

    @sooxt98

    i think my issue is coming from here, which im using the latest media_kit
    media-kit/media-kit#1289

    update:
    media-kit/media-kit@8ce5e0a

    i believe they fix the crash in latest
    media_kit: ^1.2.2
    media_kit_video: ^2.0.0

  19. sooxt98 commented on Nov 15, 2025

    @sooxt98

    i finally found the root cause,
    its the back button when quit the app,
    it will trigger this error when im using media-kit.

    what i did here is adding a PopScope to listen to back button,
    and dispose all the video player manually before quitting the app with SystemNavigator.pop()

    and i also notice another reason it crash is that,
    in latest android or flutter the back button now kill the app instead of sending it back to background like closing app with home button.

  20. Mairramer commented on Jan 2, 2026

    @Mairramer
    Contributor

    i finally found the root cause, its the back button when quit the app, it will trigger this error when im using media-kit.

    what i did here is adding a PopScope to listen to back button, and dispose all the video player manually before quitting the app with SystemNavigator.pop()

    and i also notice another reason it crash is that, in latest android or flutter the back button now kill the app instead of sending it back to background like closing app with home button.

    Interesting. In my case, it involves the camera. The flow is: camera → take photo → process. What’s strange is that dispose is configured correctly. The occurrence rate of this error is quite low, but it’s still annoying for the user when it happens. This leads me to believe it’s a race condition, specifically in this section of the code:
    https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java#L502-L521

  21. Mairramer commented on Apr 30, 2026

    @Mairramer
    Contributor

    @mboetger

    What are the consequences of adding a guard to scheduleFrame()?

    I investigated this issue, and it seems to be a race condition that occurs when FlutterJNI.scheduleFrame() or FlutterJNI.markTextureFrameAvailable() is called after the Flutter engine has already been detached from the native side.

    From Firebase, I gathered some insights from Gemini and noticed the following:

    Four active CameraX threads were running at the time of the crash:

    Thread State
    CameraX-camerax_io_0 parked (waiting for I/O)
    CameraX-core_camera_0 parked
    CameraX-core_camera_1 parked
    CameraX-scheduler polling (message queue)

    The camera was still actively running when the engine was detached. The CameraX-scheduler thread delivers frames to the Flutter texture through a SurfaceTexture callback. When it delivered a frame after the engine had already been destroyed:

    CameraX-scheduler delivers frame
      → SurfaceTexture.onFrameAvailable()
      → posts to main thread Handler
      → SurfaceTextureSurfaceProducer.scheduleFrame()
      → flutterJNI.markTextureFrameAvailable(id)
      → ensureAttachedToNative() → 💥
    

    In general, most of these crashes also seem to happen on low-end devices, accounting for around 80% of the cases.

  22. iammofidul commented on Jul 8, 2026

    @iammofidul

    Still reproducing in production on Flutter 3.44.3 stable (framework e1fd963c6f, engine 97bcd50733ba). Play-Store-distributed app, crash reported via Crashlytics:

    Fatal Exception: java.lang.RuntimeException: Cannot execute operation because FlutterJNI is not attached to native.
           at io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative(FlutterJNI.java:515)
           at io.flutter.embedding.engine.FlutterJNI.scheduleFrame(FlutterJNI.java:1025)
           at io.flutter.embedding.engine.renderer.FlutterRenderer.scheduleEngineFrame(FlutterRenderer.java:1364)
           at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer.onImage(FlutterRenderer.java:660)
           at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer$PerImageReader.lambda$new$0(FlutterRenderer.java:544)
           at android.media.ImageReader$1.run(ImageReader.java:951)
    

    The line numbers in the trace match the engine source at this revision exactly, so this is not a stale-build report. Looking at FlutterRenderer.java at e1fd963c6f, the unguarded path is visible:

    Meanwhile neighboring paths in the same class are guarded against exactly this race — L345 checks released || !flutterJNI.isAttached() and L436 checks !flutterJNI.isAttached() — which suggests this call site was simply missed.

    Since the ImageReader callback arrives on the platform thread asynchronously, it can land after FlutterJNI detaches during engine teardown (in our reports it correlates with activity destruction while a texture producer — video/camera/ad platform view — is still delivering frames). A released || !flutterJNI.isAttached() guard in scheduleEngineFrame() (or at the L660 call site, consistent with L345/L436) would appear to close the race.

  23. aykutuludag commented on Jul 25, 2026

    @aykutuludag

    Getting same error on Flutter v3.44.6. I assume it is because of I added fullscreen camera functionality with camera: ^0.12.0. Before this, I wasn't get any error.

    Fatal Exception: java.lang.RuntimeException: Cannot execute operation because FlutterJNI is not attached to native.
           at io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative(FlutterJNI.java:515)
           at io.flutter.embedding.engine.FlutterJNI.scheduleFrame(FlutterJNI.java:1025)
           at io.flutter.embedding.engine.renderer.FlutterRenderer.scheduleEngineFrame(FlutterRenderer.java:1364)
           at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer.onImage(FlutterRenderer.java:660)
           at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer$PerImageReader.lambda$new$0(FlutterRenderer.java:544)
           at android.media.ImageReader$1.run(ImageReader.java:951)
           at android.os.Handler.handleCallback(Handler.java:995)
           at android.os.Handler.dispatchMessage(Handler.java:103)
           at android.os.Looper.loopOnce(Looper.java:248)
           at android.os.Looper.loop(Looper.java:338)
           at android.app.ActivityThread.main(ActivityThread.java:9318)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:652)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
    
    Image
  24. stemonti90 commented on Aug 6, 2026

    @stemonti90

    I can reproduce this deterministically on an emulator, which may help since the reports here so far are Play Console stacks without a repro.

    Reproduction

    Any app that keeps a camera preview texture alive while the Activity is destroyed. In my case the preview comes from the camera plugin (camera_android_camerax), rendered through Texture. adb shell monkey triggers the Activity teardown reliably via --pct-appswitch:

    adb shell monkey -p <applicationId> -s 2002 --throttle 100 \
      --pct-touch 60 --pct-motion 20 --pct-trackball 0 --pct-nav 5 \
      --pct-majornav 10 --pct-syskeys 0 --pct-appswitch 3 --pct-anyevent 2 \
      --ignore-security-exceptions 1500
    

    Seed 2002 crashes roughly 1 run in 2 on a build where the camera preview is left running, at around event 1400 of 1500. Seeds 3003, 6006, 7007, 8008 also hit it at a lower rate. The seed makes the event sequence repeatable; the crash itself is a race, so it is not 100% per run.

    Stack (identical to the one reported above)

    java.lang.RuntimeException: Cannot execute operation because FlutterJNI is not attached to native.
    	at io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative
    	at io.flutter.embedding.engine.FlutterJNI.scheduleFrame
    	at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer.onImage
    	at io.flutter.embedding.engine.renderer.FlutterRenderer$ImageReaderSurfaceProducer$PerImageReader.lambda$new$0
    	at android.media.ImageReader$1.run (ImageReader.java:949)
    	at android.os.Handler.handleCallback
    	at android.os.Looper.loop
    	at android.app.ActivityThread.main
    

    The ImageReader.OnImageAvailableListener installed by PerImageReader fires on the platform thread after FlutterJNI has detached, and scheduleFrame throws instead of no-oping.

    Environment

    Flutter 3.44.0 stable, framework 559ffa3f75, engine fcf463a224
    Device emulator, sdk_gphone64_arm64, Android 15 (API 35), arm64 host (macOS)
    Camera plugin camera: ^0.12.0+1 (camera_android_camerax)
    Build debug and release, both affected

    Things I checked that did not help

    • Disabling Impeller (io.flutter.embedding.android.EnableImpeller=false) makes no difference. I initially thought it did — a 6-run sample came back clean — but that was sampling luck at a lower --pct-appswitch rate. Raising app-switch frequency reproduces it identically with Impeller off. Worth recording so nobody else spends time on that hypothesis.
    • Releasing the camera unconditionally in AppLifecycleState.detached (disposing CameraController there, even mid-capture) reduces the rate on seed 2002 from ~50% to about 1 in 6, but does not close it. detached is delivered after teardown has already begun, so an app-side release is late by construction.

    Why this can't be worked around from application code

    The ImageReader and its listener belong to ImageReaderSurfaceProducer; the application never gets a handle on either, so it cannot unregister the callback before detach. The only app-side lever is "don't have a preview texture alive", and as measured above that lever is not sufficient because the app is not told early enough.

    A guard in scheduleEngineFrame / onImage for the detached case, or unregistering the listener during ImageReaderSurfaceProducer teardown, would remove it.

    Happy to run further experiments against a patched engine if that helps — the repro is cheap and scripted.

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

    P2Important issues not at the top of the work lista: productionIssues experienced in live production appsc: crashStack traces logged to the consoleneeds repro infoAutomated crash report whose cause isn't yet knownplatform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions