Solvedflutterfire [firebase_messaging] Android v2 embedding crashes

Describe the bug
Since updating my app to the Android v2 embedding I've been getting reports in Crashlytics concerning ensureInitializationComplete must be called after startInitialization io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete.

The Flutter 1.12 upgrade guide says to remove all references to the startInitialization or ensureInitializationComplete methods but I see 2 references to these methods: here and here.

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade app to v2 embedding.
  2. Start app and then close it.
  3. Send notification from the Firebase Notification Composer.
  4. Notice app crash notification on device.
  5. See error or incorrect behavior

I have not seen the issue when I leave the app open and send the notification.

Expected behavior
Notification displayed normally while app is closed.

Additional context
Here is what the Crashlytics report looks like:

Fatal Exception: java.lang.RuntimeException
Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization ($1400 ($H.handleMessage (
android.os.Handler.dispatchMessage (
android.os.Looper.loop ( (
java.lang.reflect.Method.invoke ($ ( (

Caused by java.lang.IllegalStateException
ensureInitializationComplete must be called after startInitialization
io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete (
io.flutter.view.FlutterMain.ensureInitializationComplete (
io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate ( ($1400 ($H.handleMessage (
android.os.Handler.dispatchMessage (
android.os.Looper.loop ( (
java.lang.reflect.Method.invoke ($ ( (
49 Answers

βœ”οΈAccepted Answer

Why is this not labelled severe? This causes crash dialogs to show periodically when the application is closed, which would cause most users to either disable permissions or just delete the app. This surely should be made a priority, considering that as more and more apps/packages make the move to the v2 embedding this will affect every Android user.

Other Answers:

I have the exact same issue. The app crashes when I receive a notification while the app is closed, but I get the notification when the app is running. I migrated the app using the upgrade guide.

I tried adding android:name="" and it didnt help. The guide actually tells you to remove it.

Is there any information in regards to a release with a fix for this issues? Right now it's crashing always, as soon as the app isn't running at all (so e.g. killed by the system or swiped out of the app switcher). So the user will get crash dialogs over and over, for every push message he receives. This is something highly critical and would block any production release of an app (IMHO).
Workarounds are something we can do during testing etc., but as I'm developing a quite complex app, with different native interactions, it would be great to have a stable backbone for the push logic and setup.

Btw. thanks for the nice plugins and all the efforts integrating Flutter into the existing Firebase world. Looking forward to more nice Flutter integrations. πŸ‘

Having the same issue and it is impacting a large percentage of our users. Would appreciate a speedy fix :)

Hey all πŸ‘‹

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues.

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone.

More Issues: