Solvedflutterfire 🐛 [firebase_messaging] Can't use 3rd party plugins in background handler
✔️Accepted Answer
@asmodeoux @markusaksli-nc
Allright I'm back with a workaround.
What we will accomplish is to change the order of the GeneratedPluginRegistrant
to put all V1 in the bottom.
To do this we need to alter the flutter tools responsible for generating that file it is pretty simple.
Open the file
<flutter-sdk-location>/packages/flutter_tools/lib/src/plugins.dart
find the _writeAndroidPluginRegistrant
function and add the following snippet AFTER the call to _extractPlatformMaps:
androidPlugins.sort((Map<String, dynamic> left, Map<String, dynamic> right) {
if (left["supportsEmbeddingV2"] != right["supportsEmbeddingV2"]) {
return left["supportsEmbeddingV2"] ? -1 : 1;
}
return left["name"].compareTo(right["name"]);
});
Now we only need to rebuild flutter tools, to do that we need to remove the flutter_tools.stamp:
rm -rf <flutter-sdk-location>/bin/cache/flutter_tools.stamp
That's it, now you can flutter pub get and the GeneratedPluginRegistrant
will be sorted as we want and we will be able to use V2 embedded plugins without problems.
Bug report
Describe the bug
None of 3rd party libraries being called in onBackgroundMessage. I use version 8.0.0-dev11.
Here is my onBackgroundMessage function:
It fails to init Firebase or any other package with these logs:
When I had this error with previous versions I inited the plugins in Application.java and it worked, but now I moved to 8.0.0 and don't use Application as I have embedding v2. And, due to logs, it fails to init in onCreate.
Here is my onCreate function in MainActivity:
And Generated:
I absolutely can't use background handler because of this, so any advice would be much appreciated. I followed all the steps in every article, but can't make it works for 3 days already.
Could you explain me what happens when background event arrives sot that I could debug these files? I will provide more data if needed.
Steps to reproduce
Steps to reproduce the behavior:
Expected behavior
Any packages should be inited and available in background
Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
Flutter dependencies
Click To Expand