Repository navigation
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: productionIssues experienced in live production appsIssues experienced in live production appsc: crashStack traces logged to the consoleStack traces logged to the consoleneeds repro infoAutomated crash report whose cause isn't yet knownAutomated crash report whose cause isn't yet knownplatform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Description
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
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.Reacted by Stan, Petr Kubeš, Emilio Vega, emakar and ptuzinek
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: productionIssues experienced in live production appsIssues experienced in live production appsc: crashStack traces logged to the consoleStack traces logged to the consoleneeds repro infoAutomated crash report whose cause isn't yet knownAutomated crash report whose cause isn't yet knownplatform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Activity
darshankawar commentedon Sep 3, 2025
@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.
JonasJW commentedon Sep 3, 2025
@darshankawar thanks for the quick reply!
No, I'm not using platform views.
These are the packages I use:
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.
darshankawar commentedon Sep 4, 2025
Thanks for the update. Keeping the issue open for team's tracking.
stan-at-work commentedon Sep 4, 2025
Same here, built an AAB, uploaded it to the store, and the app crashes.
JonasJW commentedon Sep 5, 2025
Looks like I get this crash with Impeller enabled as well
stan-at-work commentedon Sep 5, 2025
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
6 remaining items
Mairramer commentedon Oct 16, 2025
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.
Mairramer commentedon Oct 17, 2025
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.
sooxt98 commentedon Oct 27, 2025
same issue here
Jezzvega commentedon Nov 10, 2025
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.
Jezzvega commentedon Nov 11, 2025
@JonasJW hey i just found this #81830
Makes sense because to implement purchases_ui_flutter you have to replace
FlutterActivitywithFlutterFragmentActivity.JonasJW commentedon Nov 11, 2025
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.
JonasJW commentedon Nov 11, 2025
@Jezzvega I'm using
purchases_flutterbut notpurchases_ui_fluttercurrentlysooxt98 commentedon Nov 13, 2025
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
sooxt98 commentedon Nov 15, 2025
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.
Mairramer commentedon Jan 2, 2026
Interesting. In my case, it involves the camera. The flow is: camera → take photo → process. What’s strange is that
disposeis 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
Mairramer commentedon Apr 30, 2026
@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()orFlutterJNI.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:
The camera was still actively running when the engine was detached. The
CameraX-schedulerthread delivers frames to the Flutter texture through aSurfaceTexturecallback. When it delivered a frame after the engine had already been destroyed:In general, most of these crashes also seem to happen on low-end devices, accounting for around 80% of the cases.
iammofidul commentedon Jul 8, 2026
Still reproducing in production on Flutter 3.44.3 stable (framework
e1fd963c6f, engine97bcd50733ba). Play-Store-distributed app, crash reported via Crashlytics: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.javaate1fd963c6f, the unguarded path is visible:ImageReaderSurfaceProducer.onImagecallsscheduleEngineFrame()at L660 with no attach-state check, andscheduleEngineFrame()itself (L1363-1365) callsflutterJNI.scheduleFrame()directly, also unguarded.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
ImageReadercallback arrives on the platform thread asynchronously, it can land afterFlutterJNIdetaches during engine teardown (in our reports it correlates with activity destruction while a texture producer — video/camera/ad platform view — is still delivering frames). Areleased || !flutterJNI.isAttached()guard inscheduleEngineFrame()(or at the L660 call site, consistent with L345/L436) would appear to close the race.aykutuludag commentedon Jul 25, 2026
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.
stemonti90 commentedon Aug 6, 2026
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
cameraplugin (camera_android_camerax), rendered throughTexture.adb shell monkeytriggers the Activity teardown reliably via--pct-appswitch:Seed
2002crashes roughly 1 run in 2 on a build where the camera preview is left running, at around event 1400 of 1500. Seeds3003,6006,7007,8008also 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)
The
ImageReader.OnImageAvailableListenerinstalled byPerImageReaderfires on the platform thread afterFlutterJNIhas detached, andscheduleFramethrows instead of no-oping.Environment
559ffa3f75, enginefcf463a224sdk_gphone64_arm64, Android 15 (API 35), arm64 host (macOS)camera: ^0.12.0+1(camera_android_camerax)Things I checked that did not help
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-appswitchrate. Raising app-switch frequency reproduces it identically with Impeller off. Worth recording so nobody else spends time on that hypothesis.AppLifecycleState.detached(disposingCameraControllerthere, even mid-capture) reduces the rate on seed 2002 from ~50% to about 1 in 6, but does not close it.detachedis 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
ImageReaderand its listener belong toImageReaderSurfaceProducer; 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/onImagefor the detached case, or unregistering the listener duringImageReaderSurfaceProducerteardown, would remove it.Happy to run further experiments against a patched engine if that helps — the repro is cheap and scripted.
fix(android): dispose video renderers on engine detach (#2192)