ably-flutter icon indicating copy to clipboard operation
ably-flutter copied to clipboard

Android application got crash on notification receive in killed state using Ably notifications

Open Asharulislam opened this issue 3 years ago • 9 comments

Now I am using latest package of Ably 1.2.15. Flutter version 2.5.3

Reference to ISSUE : https://github.com/ably/ably-flutter/issues/429

QuintinWillison ikbalkaya

If I send notifications then in Android (in terminated state) Application got crash.

Steps to reproduce:

  1. Fire 6 to 8 notifications when the app is killed.
  2. Received 2 or 4 notifications and some are still pending.
  3. Just open the App (not from tapping the notification) from apps menu.
  4. App just got crashed.

Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: io.ably.flutter.plugin. Response ID: 0 W/FlutterJNI(13840): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: io.ably.flutter.plugin. Response ID: 0 E/AndroidRuntime(13840): FATAL EXCEPTION: main E/AndroidRuntime(13840): Process: com.appiskey.dang.dev, PID: 13840 E/AndroidRuntime(13840): java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(13840): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:164) E/AndroidRuntime(13840): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:238) E/AndroidRuntime(13840): at io.ably.flutter.plugin.AblyMethodCallHandler$MethodResultWrapper.lambda$success$0$AblyMethodCallHandler$MethodResultWrapper(AblyMethodCallHandler.java:133) E/AndroidRuntime(13840): at io.ably.flutter.plugin.-$$Lambda$AblyMethodCallHandler$MethodResultWrapper$mM2gyGmNB_FxOxEa-tdyQn04YRo.run(Unknown Source:4) E/AndroidRuntime(13840): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(13840): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(13840): at android.os.Looper.loop(Looper.java:246) E/AndroidRuntime(13840): at android.app.ActivityThread.main(ActivityThread.java:8506) E/AndroidRuntime(13840): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(13840): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) E/AndroidRuntime(13840): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

h3. Some Time this error occured: FATAL EXCEPTION: main E/AndroidRuntime(18800): Process: com.appiskey.dang.dev, PID: 18800 E/AndroidRuntime(18800): java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(18800): at io.flutter.embedding.engine.o.e.a(Unknown Source:35) E/AndroidRuntime(18800): at g.b.d.a.v.b(Unknown Source:14) E/AndroidRuntime(18800): at g.a.a.a.k1.e(:1) E/AndroidRuntime(18800): at g.a.a.a.p0.run(Unknown Source:4) E/AndroidRuntime(18800): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(18800): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(18800): at android.os.Looper.loop(Looper.java:246) E/AndroidRuntime(18800): at android.app.ActivityThread.main(ActivityThread.java:8506) E/AndroidRuntime(18800): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(18800): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) E/AndroidRuntime(18800): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

┆Issue is synchronized with this Jira Bug by Unito

Asharulislam avatar Jul 20 '22 09:07 Asharulislam

Thanks for reporting this @Asharulislam. Can you please confirm that you had this issue since v1.2.15?

ikbalkaya avatar Jul 20 '22 09:07 ikbalkaya

@ikbalkaya Yes the above issue is occurred when I am using v1.2.15.

Asharulislam avatar Jul 20 '22 10:07 Asharulislam

Thank you. I will investigate

ikbalkaya avatar Jul 20 '22 10:07 ikbalkaya

A small update from me - I've looked into it today for a bit, but couldn't find a way to reproduce this crash (tried using the example app with various emulators and a physical device, hasn't crashed once).

I'm leaving Ably, so for whomever looks at it in the future - since it seems like this started happening since v. 1.2.15, it might be connected to the ably-java version bump (unlikely): https://github.com/ably/ably-flutter/pull/435 Or more likely - to using the main thread to send messages to Flutter plugin, which might cause ANRs again: https://github.com/ably/ably-flutter/pull/431/files

Please keep in mind that all those issues might become irrelevant once we switch to the federated plugin approach, but that will probably take a while.

JakubJankowski avatar Mar 29 '23 14:03 JakubJankowski

The corresponding Jira issue is https://ably.atlassian.net/browse/SDK-2480

deanna-lad avatar Apr 03 '23 12:04 deanna-lad

@Asharulislam Could you provide Android version that causes this issue please? For the note I tested this on Android 11 and 13. It turns out that

  • Android 11 does not receive notification after termination, but no crash happens on app start (or re-start)
  • Android 13 does receive notification and there is also no issue with push messages

ikbalkaya avatar Apr 04 '23 19:04 ikbalkaya

@ikbalkaya My android version was 12.

Ably version 1.2.15. Flutter version 2.5.3

Asharulislam avatar Apr 05 '23 07:04 Asharulislam

Thanks @Asharulislam. I just did another test with

  • ably-flutter 1.2.15
  • Flutter 2.5.3 and
  • Android 12

The behaviour was similar to the one as Android 11. Notifications aren't received but I did not experience a crash on app startup. When I was doing initial testing I realized the Flutter version was 2.8.0 - Would it be possible for you to increase your Flutter version and give it another go and see whether you are having a similar issue. In the meantime I realize that not receiving push messages when the app is terminated is another issue and I'm going to look into addressing it.

Also please could you try using a release build of your app when testing push notifications on terminated state?

ikbalkaya avatar Apr 05 '23 11:04 ikbalkaya

if you open "Auto start" setting, you will receive message even if app is closed. Howerer, ably will start a new flutter engine to transport message to flutter. I think it's useless. To fix this problem , you can remove default FIrebaseMessageReceiver and remove ManuFlutterXXXX invoke.

YumengNevix avatar Sep 15 '23 06:09 YumengNevix