Skip to content

Commit 28433c5

Browse files
FlutterJNI no longer asserts it is attached when dispatching platform messages and instead fizzles with a warning if not attached. Not sure what root cause of issue is, but this is necessary to avoid crashes. (flutter#8246)
1 parent 1addfb5 commit 28433c5

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,11 @@ private native void nativeRunBundleAndSnapshotFromLibrary(
461461

462462
@UiThread
463463
public void dispatchEmptyPlatformMessage(String channel, int responseId) {
464-
ensureAttachedToNative();
465-
nativeDispatchEmptyPlatformMessage(nativePlatformViewId, channel, responseId);
464+
if (isAttached()) {
465+
nativeDispatchEmptyPlatformMessage(nativePlatformViewId, channel, responseId);
466+
} else {
467+
Log.w(TAG, "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: " + channel + ". Response ID: " + responseId);
468+
}
466469
}
467470

468471
// Send an empty platform message to Dart.
@@ -474,14 +477,17 @@ private native void nativeDispatchEmptyPlatformMessage(
474477

475478
@UiThread
476479
public void dispatchPlatformMessage(String channel, ByteBuffer message, int position, int responseId) {
477-
ensureAttachedToNative();
478-
nativeDispatchPlatformMessage(
479-
nativePlatformViewId,
480-
channel,
481-
message,
482-
position,
483-
responseId
484-
);
480+
if (isAttached()) {
481+
nativeDispatchPlatformMessage(
482+
nativePlatformViewId,
483+
channel,
484+
message,
485+
position,
486+
responseId
487+
);
488+
} else {
489+
Log.w(TAG, "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: " + channel + ". Response ID: " + responseId);
490+
}
485491
}
486492

487493
// Send a data-carrying platform message to Dart.

0 commit comments

Comments
 (0)