Closed Droyder7 closed 7 months ago
Hey @Droyder7 thank you for your great job, I have no idea how this issue happened. I will take a look.
Hey @Droyder7 thank you for your great job, I have no idea how this issue happened. I will take a look.
No worries, I'm happy to help. Actually this issue can be reproduced in the example app itself, here are the steps:
flutter logs
for checking logsIt will crash after sending the NotificationEvent
through the send port. For more details you can also check the attached issues.
Thanks for appreciating my contribution, please let me know if you need any other clarification in order to merge this PR.
@Droyder7 @jiusanzhou Hi, I am new to flutter. Would you mind explaining how to implement the fix? I need it for a project that I am working on
@Droyder7 @jiusanzhou Hi, I am new to flutter. Would you mind explaining how to implement the fix? I need it for a project that I am working on
Hi @Jace-Joji , Ideally you have to wait for this fix to be merged in the main repo but for the mean time you can use my repo as source in flutter dependency. Just add the following lines in dependencies
section in pubspec.yaml
file of your flutter project:
flutter_notification_listener:
git:
url: https://github.com/Droyder7/flutter_notification_listener.git
@Droyder7 @jiusanzhou Hi, I am new to flutter. Would you mind explaining how to implement the fix? I need it for a project that I am working on
Hi @Jace-Joji , Ideally you have to wait for this fix to be merged in the main repo but for the mean time you can use my repo as source in flutter dependency. Just add the following lines in
dependencies
section inpubspec.yaml
file of your flutter project:flutter_notification_listener: git: url: https://github.com/Droyder7/flutter_notification_listener.git
Hi, I'm using the package pointing to your repository but I'm still getting the error.
@Droyder7 you package works fine in debug mode but not working in release mode. Not able to listen to notification when app is terminated in release mode. I get same error @jesselpereira
@Droyder7 you package works fine in debug mode but not working in release mode. Not able to listen to notification when app is terminated in release mode. I get same error @jesselpereira
It's true, I didn't experience any hindrances while in debug mode, but when uploading to the Google Play Store I received notifications from Firebase Crashlytics.
It would be perfect if it were corrected.
Hi @jesselpereira, Thanks for pointing out this issue, the destroy method your App's activity is crashing while terminating the app as the flutter engine should not be destroyed when the flutterJNI is attached to native.
So, we have to prevent the app from trying to destroy the flutter engine when terminating the app, some additional changes may needs to be done on the app side in order to fix this.
Overwrite the below mentioned code in the MainActivity.kt file of the android app :
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
override fun shouldDestroyEngineWithHost(): Boolean = false
}
Let me know if it solves the issue or not, Thanks.
Hi @jesselpereira, Thanks for pointing out this issue, the destroy method your App's activity is crashing while terminating the app as the flutter engine should not be destroyed when the flutterJNI is attached to native.
So, we have to prevent the app from trying to destroy the flutter engine when terminating the app, some additional changes may needs to be done on the app side in order to fix this.
Overwrite the below mentioned code in the MainActivity.kt file of the android app :
import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterActivity() { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); } override fun shouldDestroyEngineWithHost(): Boolean = false }
Let me know if it solves the issue or not, Thanks.
I applied the change and it really worked, the exception disappeared! Thank you very much for the solution.
Please, if you are interested, could you take a look at #47 and tell me if this case is possible?
[ERROR:flutter/shell/common/shell.cc(117)] Dart Error: Dart_LookupLibrary: library 'package:flutter_notification_listener/src/plugin.dart' not found.
E/flutter (19660): [ERROR:flutter/runtime/dart_isolate.cc(677)] Could not resolve main entrypoint function.
E/flutter (19660): [ERROR:flutter/runtime/dart_isolate.cc(168)] Could not run the run main Dart entrypoint.
E/flutter (19660): [ERROR:flutter/runtime/runtime_controller.cc(462)] Could not create root isolate.
E/flutter (19660): [ERROR:flutter/shell/common/shell.cc(669)] Could not launch engine with configuration.
I am getting this error when I close the app and then background callback is not working, It's working fine in debug, error was in when we run the app in release mode Issue can we generate in example app
Fixes #18 , #35, #45
Issue Description:
when the app is closed from the recent app menu, and a notification is posted, it seems like the listener has a broken channel connection and the dart code does not run, and produces the error message :
"Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter_notification_listener/bg_method"
Fix Details:
Incorporated JNI objects into the plugin code. JNI allows Java code to interact with applications and libraries written in other languages, such as C++. By managing the JNI lifecycle properly, we can avoid detachment issues and ensure a smooth communication flow between Flutter and native code