Flutterfire: [firebase_messaging] Android v2 embedding crashes

Created on 2 Jan 2020  ·  96Comments  ·  Source: FirebaseExtended/flutterfire

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
android.app.ActivityThread.handleCreateService (ActivityThread.java:3746)
android.app.ActivityThread.access$1400 (ActivityThread.java:235)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1784)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:6986)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1445)

Caused by java.lang.IllegalStateException
ensureInitializationComplete must be called after startInitialization
io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete (FlutterLoader.java:153)
io.flutter.view.FlutterMain.ensureInitializationComplete (FlutterMain.java:80)
io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate (FlutterFirebaseMessagingService.java:71)
android.app.ActivityThread.handleCreateService (ActivityThread.java:3734)
android.app.ActivityThread.access$1400 (ActivityThread.java:235)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1784)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:6986)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1445)
crowd messaging bug documentation

Most helpful comment

Dev release very, very soon ;)

All 96 comments

Closing this. Seems that I had left android:name="io.flutter.app.FlutterApplication" out of my <application> definition in AndroidManifest.xml.

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="io.flutter.app.FlutterApplication" and it didnt help. The guide actually tells you to remove it.

Please reopen the issue because the problem still remain

Please reopen the issue I am facing the same thing as well!

Reopened. Should not have closed it.

Anyone with a solution for this? Having the same problem.

I'm seeing this also

I have the same problem

The bug happens because the plugin still calling FlutterMain.ensureInitializationComplete which it shouldn't do with the new v2 embedding. The 1.12 migration guide says:

If you invoke FlutterMain.startInitialization(...) or FlutterMain.ensureInitializationComplete(...) anywhere in your code, you should remove those calls. Flutter now initializes itself at the appropriate time.

So the "ensureInitializationComplete must be called after startInitialization" error happens because the plugin is calling ensureInitializedComplete when under v2, startInitialization is never called.

Until this is fixed, you can get around the error by making your app use the old io.flutter.app.FlutterApplication class as your application class, or if you have your own custom application class, you can either make it extend FlutterApplication or you can just call startInitialization in your own application class's onStart (which is what FlutterApplication basically does.)

I'm having this issue too, unfortunately I can't go back and revert the v2 embedding implementation in my app because other plugins depend on it to work properly.

Any chance to fix this soon? This issue is quite old now...

I'm having the same issue too! Can we get it fixed soon?

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

I'm having this issue as well

You may as well try the workaround I described in my post above. Just to clarify, this workaround does NOT require you to revert your project to pre-v2.

@ryanheise How about those in GeneratedPluginRegistrants? Some of my package use those do I need to include that in MainActivity.kt?

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. 👍

Issues related to this problem (it seems that general parts are missing for the Android v2 embedding: setup call adjustments, documentation and some internal handling e.g. for plugin calls in the onBackgroundMessage method):

Only did a really short search, so probably there are more related issues. Just wanted to show that this problem is probably affecting a larger number of developers and users than visible in this particular ticket.

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.

I don't know how but I solved it mysteriously. 🧐

2510 also seems to be related. Please - PRETTY PLEASE make this is a priority.

2468 also seems to be related.

I was able to fix this issue when pressing on notifications by doing this, but please read the entire post before continuing.

This is what fixed the issue for me:
Add this to the application tag: android:name="io.flutter.app.FlutterApplication"

Here is my application tag

<application
        android:name="io.flutter.app.FlutterApplication"
        tools:replace="android:label"
        android:label="App Name"
        android:icon="@mipmap/ic_launcher">

My primary activity for the app is this

<activity
            android:name="io.flutter.embedding.android.FlutterActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"

            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <!--FIREBASE CLOUD MESSAGING-->
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

I also included these tags under application, among other various widgets.

<meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

I sent a notification through a notification channel "test_channel" using the firebase console and the app did not crash when I pressed the notification; it properly entered the app. I did not test if data was received properly, but I would assume it works because it no longer crashes.

https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
This upgrade guide indicates to remove android:name="io.flutter.app.FlutterApplication" from the application tag. Adding it back in seems to fix the firebase bug, but it seems like it still functions fine with it added back in, even using v2 embedding. It seems to be working fine with all of my V2 plugins and background_fetch also is working fine as far as I can tell. This could be a temporary fix until the issue is addressed properly?

Please do test it out for yourself because this goes against the update guidelines which tell you to remove this.

Hi @MooNag
I have this fix in production for weeks and my users are happy. So I'm assuming it is safe.

@MooNag This just reverts one of the steps required to update to Android v2 embedding.
This fix won't work for those who require the new v2 embedding and want to receive notifications.

@MichaelM97 Yeah I am aware. I said that, but it is compatible with the V2 embedding, and plugin setup, as well as fixing the crashes with FCM. It is a fix, not the correct solution to the problem, until the issue can be patched on either Flutter's end, or on the plugin side of things. Note that I am still using the v2 embedding in my project and notifications are working.

Does this fix not work for you? It would be good to note compatibility issues if they exist.

@helenaford this issue is blocking us to release, is there any workaround that can prevent our app to crash when receiving a notification when our app is closed?

Yes @Zazo032 , the workaround is described several times in previous comments.

@MooNag @estevez-dev am I assuming right that both of you aren't using the onBackgroundMessage callback of the configure method (https://pub.dev/documentation/firebase_messaging/latest/firebase_messaging/FirebaseMessaging/configure.html)?
Without the callback everything looks okay during start, but as soon the callback is added the workaround breaks (firebase_messaging: ^6.0.15 is used).

As required parts are missing for the real v2 embedding the following exception is thrown:

E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133): java.lang.RuntimeException: PluginRegistrantCallback is not set.
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:157)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.onMethodCall(FirebaseMessagingPlugin.java:176)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 7133):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Btw. thanks for the efforts to workaround this problem @MooNag !

Edit:
Already tried to implement my own class extending io.flutter.app.FlutterApplication and doing the registration for the background stuff there. Result: not stable / not working

Hey @Boehrsi, you are right, I'm not using background messages handling.

@FirebaseExtended/invertase at first thanks for taking over the
FirebaseExtended maintenance (via https://github.com/FirebaseExtended/flutterfire/issues/2582). 👍
At second and as mentioned in the issue, if we have some important issues in mind we should ping you. This comment is more or less exactly this.

Even though FCM and the cloud messaging part isn't your highest priority, it would be awesome to have full fledged push support in Flutter, even if the app isn't running at all.
Without comprehensive push support neither chat apps, nor mail apps or other user interaction heavy apps can be realized completely.
I selected this specific issue, but I also linked interconnected ones (https://github.com/FirebaseExtended/flutterfire/issues/1754#issuecomment-621164872) and there are probably more. It's about both the actual functionality and also the documentation part.

If there is anything that can be done by me / us please just respond, as I would happily provide use cases, actual problems or a more comprehensive error description if helpful. If possible I would also like to contribute to the problem itself, but right now I don't think that trail / error approaches in such a core component of an ecosystem would be helpful.

Probably also related to this topic (general v2 embedding problems): https://github.com/FirebaseExtended/flutterfire/issues/2111 (embedding v2 + data message, but the app is not even killed, it's just in the background. Is not crashing, but not working nevertheless).

So that developers have more information:

(Android Flutter Update Challenges)

We have an application that we started on Flutter 1.7(ish). We were on (v1.12.13+hotfix.8) when 1.17.X came out. We waited until we had released a big batch of features before updating Flutter. We released the features. Waited a week. All good. So, I decided to update Flutter/Dart (_and_ all of our dependencies).

When I got to updating barcode_scan, I read through the change log and followed all update instructions. The barcode_scan upgrade instructions linked to the Flutter Upgrading pre 1.12 Android projects instructions. So, I followed those.

Later I got down to firebase_messaging. I updated to the most current of that too (^6.0.16). After updating, I _thought_ everything was working until I closed the app (swiped out of open app list) and sent a notification. I got an app crash notification. I tried reverting to the older version of firebase_messaging that we had been using (5.1.8). That did not fix it.

What did fix it (but, feels wrong) was to add back android:name="io.flutter.app.FlutterApplication" (which the Flutter upgrade pre 1.12 instructions said to remove).

Given that I had removed the android.name attribute while following update instructions for the barcode_scan and image packages, I built a prod build, and tested barcode scanning, the camera, and notifications. With that attribute added back, the image, barcode_scan, and firebase_messaging plugins are all working (for me in Android).

It get that YYMV. And I would rather not do something against the upgrade instructions. But, this is how I'm going to leave it for now. Looking forward to hearing if there is a better long term solution.

Just for reference. Here is my Flutter Doctor.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.4, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.46.1)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.

I have facing this issue the google crashlytics catch these issues
Screen Shot 2020-07-12 at 11 18 29 AM
Screen Shot 2020-07-12 at 11 18 39 AM

@niypoo The bug that you posted is the following: https://github.com/flutter/flutter/issues/37566

This is the suggested fix: https://github.com/flutter/flutter/issues/37566#issuecomment-647800555

@niypoo The bug that you posted is the following: flutter/flutter#37566

This is the suggested fix: flutter/flutter#37566 (comment)

thanks @philipgiuliani I will try that suggested fix

@niypoo The bug that you posted is the following: flutter/flutter#37566

This is the suggested fix: flutter/flutter#37566 (comment)

Does not work for me... It still crashes when the app is terminated and recieves a notification.

Hello guys, i'm having this issue too in a production environment, really need help, background notification is essential for my app, started after upgrading for android embedding v2, I have also updated to the latest version fo firebase_messaging package ^7.0.0.

Crashlytics:

Fatal Exception: java.lang.RuntimeException Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set. android.app.ActivityThread.handleCreateService

EmbeddingV1Activity:
`package br.com.spacerocket.constante
import android.os.Bundle
import io.flutter.app.FlutterActivity
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin

class EmbeddingV1Activity: FlutterActivity() {
override protected fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
FirebaseMessagingPlugin.registerWith(registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
}
}`

Android Manifest:

` xmlns:tools="http://schemas.android.com/tools"
package="br.com.spacerocket.constante">

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:label="Constante"
    android:name="io.flutter.app.FlutterApplication"
    android:icon="@mipmap/ic_launcher"
    >
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
    <!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
    <meta-data
     android:name="com.google.firebase.messaging.default_notification_icon"
     android:resource="@drawable/ic_notification" />

     <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message.  -->
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />   

    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">

        <!-- Specify that the launch screen should continue being displayed -->
        <!-- until Flutter renders its first frame. -->
        <meta-data
            android:name="io.flutter.embedding.android.SplashScreenDrawable"
            android:resource="@drawable/launch_background" />

        <!-- Theme to apply as soon as Flutter begins rendering frames -->
        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme"
            />

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="FLUTTER_NOTIFICATION_CLICK" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>

    <!--keep compatibility -->
    <activity
        android:name=".EmbeddingV1Activity"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
    </activity>

    <!-- Facebook Login configuration -->
    <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" 
        android:exported="true"
        />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.vending.BILLING" />


`

I have the same problem Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization

There are multiple issues with fcm plugin. IllegalStateException can be solved by following recipe:

create application class

Kotlin:

class WorkaroundApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        FlutterMain.startInitialization(this)
        FlutterFirebaseMessagingService.setPluginRegistrant {}
    }
}


set this class as application class in Android manifest

<application
            android:name=".WorkaroundApplication"
            android:label="@string/app.name"
            android:icon="@mipmap/ic_launcher"
            android:allowBackup="false"
    >

there is complicated issue when application process is stopped and notification comes. Background notifications processing (in flutter) does not work and will not probably soon or ever work when application process is stopped. With this workaround there will be at least shown tray notification and background notification will crash in flutter code, not Android so Android process will not be crashed (which has further unpleasant consequences).

The firebase_messaging plugin is not ready for Android v2 embedding. For that, they should:

  1. Remove the references to _FlutterMain.ensureInitializationComplete_ which is called twice in the java code.
  2. Change _FlutterNativeView_ related code to _FlutterEngine_ related code.
  3. Change _pluginRegistrantCallback_ mandatory requirement to optional (since it will only be used in v1 embedding)

For now, you must use v1 embedding as described in their README or modify the FlutterFirebaseMessagingService.java file on your local plugins folder with the above instructions.

I have created a PR#3572 that should fix this issue if you are using v2 embedding (i.e. you removed the .Application reference in your manifest). Let me know if this is working for you

@jronceroscb hello, i tested here and i'm getting this error when sending notification:

java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference E/AndroidRuntime(25801): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3544) E/AndroidRuntime(25801): at android.app.ActivityThread.access$1300(ActivityThread.java:199) E/AndroidRuntime(25801): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666) E/AndroidRuntime(25801): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(25801): at android.os.Looper.loop(Looper.java:193) E/AndroidRuntime(25801): at android.app.ActivityThread.main(ActivityThread.java:6669) E/AndroidRuntime(25801): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(25801): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/AndroidRuntime(25801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) E/AndroidRuntime(25801): Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference E/AndroidRuntime(25801): at io.flutter.embedding.engine.dart.DartExecutor$DartCallback.toString(DartExecutor.java:325) E/AndroidRuntime(25801): at java.lang.String.valueOf(String.java:2896) E/AndroidRuntime(25801): at java.lang.StringBuilder.append(StringBuilder.java:132) E/AndroidRuntime(25801): at io.flutter.embedding.engine.dart.DartExecutor.executeDartCallback(DartExecutor.java:141) E/AndroidRuntime(25801): at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:170) E/AndroidRuntime(25801): at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:85) E/AndroidRuntime(25801): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3532)

Hi @juzejunior , can you elaborate?
What is your flutter version? How are you setting up Firebase Messaging? What is your Android MainActivity/Application and your manifest?

From your log, I see executions at lines that are not right for the FlutterFirebaseMessagingService.java file (85 is not onCreate and 170 shouldnt crash at all)

While it is not fixed, the following workaround solved the issue for me:

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.FlutterInjector;
import androidx.annotation.CallSuper;

public class MainActivity extends FlutterActivity {

    @Override
    @CallSuper
    protected void onStart() {
        super.onStart();
        FlutterInjector.instance().flutterLoader().startInitialization(this);
    }
}

Hi @jronceroscb, first of all, thank you for your effort!

I just tried to use your PR by directly referencing your fork in pubspec.yml. I get the same error as juzejunior, but with correct line numbers, see below. Maybe this helps.

I do have a customized FlutterActivity, as I am offering a "share" functionality in my app.

Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale de-DE)

W/FlutterEngine(29300): Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@1f6857e) but could not find and invoke the GeneratedPluginRegistrant.
D/AndroidRuntime(29300): Shutting down VM
E/AndroidRuntime(29300): FATAL EXCEPTION: main
E/AndroidRuntime(29300): Process: com.klubraum.androidApp.dev, PID: 29300
E/AndroidRuntime(29300): java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime(29300):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4412)
E/AndroidRuntime(29300):    at android.app.ActivityThread.access$1800(ActivityThread.java:274)
E/AndroidRuntime(29300):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118)
E/AndroidRuntime(29300):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(29300):    at android.os.Looper.loop(Looper.java:237)
E/AndroidRuntime(29300):    at android.app.ActivityThread.main(ActivityThread.java:8154)
E/AndroidRuntime(29300):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(29300):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E/AndroidRuntime(29300):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
E/AndroidRuntime(29300): Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime(29300):    at io.flutter.embedding.engine.dart.DartExecutor$DartCallback.toString(DartExecutor.java:325)
E/AndroidRuntime(29300):    at java.lang.String.valueOf(String.java:2924)
E/AndroidRuntime(29300):    at java.lang.StringBuilder.append(StringBuilder.java:132)
E/AndroidRuntime(29300):    at io.flutter.embedding.engine.dart.DartExecutor.executeDartCallback(DartExecutor.java:141)
E/AndroidRuntime(29300):    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:165)
E/AndroidRuntime(29300):    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:80)
E/AndroidRuntime(29300):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4400)
E/AndroidRuntime(29300):    ... 8 more



Hi @jronceroscb, first of all, thank you for your effort!

I just tried to use your PR by directly referencing your fork in pubspec.yml. I get the same error as juzejunior, but with correct line numbers, see below. Maybe this helps.

I do have a customized FlutterActivity, as I am offering a "share" functionality in my app.

Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale de-DE)

W/FlutterEngine(29300): Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@1f6857e) but could not find and invoke the GeneratedPluginRegistrant.
D/AndroidRuntime(29300): Shutting down VM
E/AndroidRuntime(29300): FATAL EXCEPTION: main
E/AndroidRuntime(29300): Process: com.klubraum.androidApp.dev, PID: 29300
E/AndroidRuntime(29300): java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime(29300):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:4412)
E/AndroidRuntime(29300):  at android.app.ActivityThread.access$1800(ActivityThread.java:274)
E/AndroidRuntime(29300):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118)
E/AndroidRuntime(29300):  at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(29300):  at android.os.Looper.loop(Looper.java:237)
E/AndroidRuntime(29300):  at android.app.ActivityThread.main(ActivityThread.java:8154)
E/AndroidRuntime(29300):  at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(29300):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E/AndroidRuntime(29300):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
E/AndroidRuntime(29300): Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime(29300):  at io.flutter.embedding.engine.dart.DartExecutor$DartCallback.toString(DartExecutor.java:325)
E/AndroidRuntime(29300):  at java.lang.String.valueOf(String.java:2924)
E/AndroidRuntime(29300):  at java.lang.StringBuilder.append(StringBuilder.java:132)
E/AndroidRuntime(29300):  at io.flutter.embedding.engine.dart.DartExecutor.executeDartCallback(DartExecutor.java:141)
E/AndroidRuntime(29300):  at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:165)
E/AndroidRuntime(29300):  at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:80)
E/AndroidRuntime(29300):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:4400)
E/AndroidRuntime(29300):  ... 8 more

The "_Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@1f6857e) but could not find and invoke the GeneratedPluginRegistrant._" line suggests me that you are not using the v2 embedding in your manifest, i.e. you don't have

<meta-data android:name="flutterEmbedding" android:value="2" />

inside your application node. Can you confirm this?

Anyways, the plugin should also work with v1 embedding, so, can you share some of that Flutter Activity (Main Activity) code to reproduce on my end?

And thanks for taking the effort to test my fork!

Can you confirm this?

Unfortunately I cannot confirm this. I had switched to v2 embedding completely, exactly according to the guide, and meanwhile rely on the workaround described by MooNag. Maybe it is because I have a custom FlutterActivity?

If I can help you with any further information, let me know.

Regards, Steffen

Can you confirm this?

Unfortunately I cannot confirm this. I had switched to v2 embedding completely, exactly according to the guide, and meanwhile rely on the workaround described by MooNag. Maybe it is because I have a custom FlutterActivity?

If I can help you with any further information, let me know.

Regards, Steffen

Thanks again Steffen for answering. Let's see if we can manage to reproduce your environment on my end to fix this. If you can provide me some code of your:

  • Manifest: application node and activity node referencing your custom FlutterActivity.
  • Your custom FlutterActivity onCreate/configureFlutterEngine code.
  • Your custom Application onCreate/registerWith code (if you have this file).

Thanks in advance

Sounds like a good plan :) Thanks once again for trying to solve this puzzle!

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- permissions needed for multi_image_picker -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


    <application
        android:label="${applicationLabel}"
        android:icon="@mipmap/ic_launcher"
        android:allowBackup="false"
        android:fullBackupContent="false">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no ui.components.splash screen (such as the default ui.components.splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />

            <!-- Theme to apply as soon as Flutter begins rendering frames -->
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
                />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <!-- Firebase Messaging -->
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <!-- App Links (Login-Link, Conversations) -->
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="https"
                    android:host="${appLinkHost}" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="image/png"/>
                <data android:mimeType="image/jpeg"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND_MULTIPLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="image/png"/>
                <data android:mimeType="image/jpeg"/>
            </intent-filter>
        </activity>
        <activity
            android:name="com.yalantis.ucrop.UCropActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        </activity>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <meta-data android:name="com.google.android.geo.API_KEY"
            android:value="**************"/>
</application>
</manifest>

MainActivity.class

package com.example.app;

import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
import com.example.app.plugins.share.FlutterShareReceiverActivity;

import android.util.Log;

public class MainActivity extends FlutterShareReceiverActivity {

  @Override
  protected void registerPlugins(@NonNull FlutterEngine flutterEngine) {
    Log.i(getClass().getSimpleName(), "initializing plugins");
    GeneratedPluginRegistrant.registerWith(flutterEngine);
  }
}

FlutterShareReceiverActivity is located in a separate plugin and contains the following code:

public abstract class FlutterShareReceiverActivity extends FlutterActivity {

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        registerPlugins(flutterEngine);
        if (!inited) {
            init(flutterEngine, this);
        }
        handleIntent(getIntent());
    }

    protected abstract void registerPlugins(@NonNull FlutterEngine flutterEngine);

    public void init(@NonNull FlutterEngine flutterEngine, Context context) {
        Log.i(getClass().getSimpleName(), "initializing share eventChannel");
        //omitted

     }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleIntent(intent);
    }

    public void handleIntent(Intent intent) {
       //omitted
    }
}

I tried to remove all unrelated code above. Hope this still provides enough information.

Cheers, Steffen

@steffenhaak I've tested with your exact custom activity setup and it's working perfectly fine.

Is that share plugin publicly available? I've checked _flutter-share_ and _ShareImage-Flutter_ repos but they don't have exactly the same code that you've posted.

Thanks again

Hey @jronceroscb . Sorry for the late response. I had to urgently jump into another crucial issue.

The plugin has some minor changes that definitely should not relate to the error thrown. If I find the the time, I will try to replicate the issue with the original share receiver plugin and see if the error is still there.

I have created a PR#3572 that should fix this issue if you are using v2 embedding (i.e. you removed the .Application reference in your manifest). Let me know if this is working for you

Is there any news on the above mentioned fix being merged?

As of the latest stable release for Flutter 1.22.0 it is now being enforced that we switch to the new Android v2 Embedding, which this plugin is preventing us from doing. @Ehesp @Salakar @kroikie

Running "flutter pub get"...                               2.9s
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project.

@Ehesp @Salakar @kroikie

Also, the official FlutterFire Facebook auth docs point developers to using the flutter_facebook_auth package, however, this package causes a runtime crash on Android unless you have migrated to the v2 embedding.

Therefore, it is not possible to use firebase_messaging and flutter_facebook_auth together as both will cause crashes dependening on if you have or have not migrated to the Android v2 embedding.

I encountered the same problem after migrating to v2 embedding.

E/AndroidRuntime(30267): java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization
E/AndroidRuntime(30267):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3173)
E/AndroidRuntime(30267):    at android.app.ActivityThread.access$1900(ActivityThread.java:177)
E/AndroidRuntime(30267):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1513)
E/AndroidRuntime(30267):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(30267):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(30267):    at android.app.ActivityThread.main(ActivityThread.java:5910)
E/AndroidRuntime(30267):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(30267):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(30267):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
E/AndroidRuntime(30267):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
E/AndroidRuntime(30267): Caused by: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization
E/AndroidRuntime(30267):    at io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete(FlutterLoader.java:174)
E/AndroidRuntime(30267):    at io.flutter.view.FlutterMain.ensureInitializationComplete(FlutterMain.java:78)
E/AndroidRuntime(30267):    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:71)
E/AndroidRuntime(30267):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3163)

Are you planning fixing this and can you give any estimation when it will happen, so we can decide whether to revert the v2 migration or not?

Hi @jronceroscb, first of all, thank you for your effort!

I just tried to use your PR by directly referencing your fork in pubspec.yml. I get the same error as juzejunior, but with correct line numbers, see below. Maybe this helps.

I do have a customized FlutterActivity, as I am offering a "share" functionality in my app.

Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale de-DE)

W/FlutterEngine(29300): Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@1f6857e) but could not find and invoke the GeneratedPluginRegistrant.
D/AndroidRuntime(29300): Shutting down VM
E/AndroidRuntime(29300): FATAL EXCEPTION: main
E/AndroidRuntime(29300): Process: com.klubraum.androidApp.dev, PID: 29300
E/AndroidRuntime(29300): java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime(29300):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:4412)
E/AndroidRuntime(29300):  at android.app.ActivityThread.access$1800(ActivityThread.java:274)
E/AndroidRuntime(29300):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118)
E/AndroidRuntime(29300):  at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(29300):  at android.os.Looper.loop(Looper.java:237)
E/AndroidRuntime(29300):  at android.app.ActivityThread.main(ActivityThread.java:8154)
E/AndroidRuntime(29300):  at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(29300):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E/AndroidRuntime(29300):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
E/AndroidRuntime(29300): Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime(29300):  at io.flutter.embedding.engine.dart.DartExecutor$DartCallback.toString(DartExecutor.java:325)
E/AndroidRuntime(29300):  at java.lang.String.valueOf(String.java:2924)
E/AndroidRuntime(29300):  at java.lang.StringBuilder.append(StringBuilder.java:132)
E/AndroidRuntime(29300):  at io.flutter.embedding.engine.dart.DartExecutor.executeDartCallback(DartExecutor.java:141)
E/AndroidRuntime(29300):  at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:165)
E/AndroidRuntime(29300):  at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:80)
E/AndroidRuntime(29300):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:4400)
E/AndroidRuntime(29300):  ... 8 more

I faced the same issue today, so i created a fork of the PR created by @jronceroscb and pushed to my repo with some changes and fixes
https://github.com/mondoktamas/flutterfire/tree/support-android-v2-embedding

Please note that to make it work properly on flutter side you have to set the onBackgroundMessage callback as a static or top-level function. Otherwise, you will not receive the pushes when your app is terminated.

  static Future<void> onBackgroundMessage(Map<String, dynamic> message) async {
    print(message);
  }

  void _subscribeToPushMessages() {
    final firebaseMessaging = FirebaseMessaging();
    firebaseMessaging.configure(onBackgroundMessage: onBackgroundMessage);
  }

I am facing the exat same errors as @juzejunior and @mondoktamas when using @jronceroscb 's fork. I tried your fork @mondoktamas and it works when the app is either killed or in background, however my onMessage handler is never called when the app is in foreground and I send a push notification.

@savy-91 i just double checked on my side, and the onMessage works for me as expected. Can you share the code you used, or maybe some logs when the app is in foreground?

@savy-91 just remembered that I removed the FlutterFirebaseMessagingService registration in the AndroidManifest.xml file. Just reverted it and pushed to my fork, it may cause the issue you described above.

FYI 🥳

Screenshot 2020-10-09 at 10 15 16

@MichaelM97 Yep, being worked on right now. https://github.com/invertase/flutterfire/pull/76 is the branch (WIP) we have going, we keep the first comment up-to-date with the changes so we can port it to the migration guide.

@Ehesp thanks for your efforts. Although I was excited when I saw the mention of "background iOS messaging handling support", after checking the code, it isn't quite what I had hoped for. This one line causes untold problems in apps that run in the background. Each instance of the plugin should store the method channel for communicating with its respective FlutterEngine, but this line actually stores the channel in a single global variable and thus each new instance of the plugin overwrites the previously stored one and forgets how to communicate with the FlutterEngine that was originally receiving the messages (see #3671).So in practice, cloud_firestore will fail to send messages in any app that executes Dart code in the background.

Yeah that code is pretty much untouched, @Salakar has full native rework incoming. And also on the singleton issue, that is one on our radar which we're aware of, just need some time put in to fix it.

same issue with flutter 1.22.1 and firebase_messaging: ^7.0.3

@TahaTesser any fix from flutter its breaks backward compatibility

Fatal Exception: java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: dlopen failed: couldn't map "/mnt/asec/kw.ltd.barcodeapp-1/split_config.armeabi_v7a.apk!/lib/armeabi-v7a/libflutter.so" segment 2: Permission denied
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3554)
at android.app.ActivityThread.-wrap4()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6942)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

same issue with flutter 1.22.2

Is firebase_messaging update can be expected soon?

image

Dev release very, very soon ;)

@Ehesp any update on this ? Thanks 😄

@Ehesp is that 8.0.0-dev.1?

@vanlooverenkoen tried that version yesterday and get a lot of deprecated methods configure, iosRegistered , maybe he still working on this.

You need to use FirebaseMessaging.instance now. for everything I got the dartcode working. But I couldn't run because the java code could not be compiled

make sense... let's wait for Elliot input on this.

Replacing this is the fix that I will use for now:

Creating custom Application that extends Flutter Application & adding it to the AndroidManifest.xml

Changing the firebase_messaging dependency to:

  firebase_messaging:
    git:
      url: git://github.com/mondoktamas/flutterfire
      branch: support-android-v2-embedding
      path: packages/firebase_messaging

=>>> This wasn't working for iOS 😑

Yeah we've removed a few things (specifically configure) since it was too easy to cause unwanted side effects from simply calling it more than once etc.

We're going to push another release soon with some more changes. Note; the Firebase SDKs need updating in version so we've also got to bump all other package versions... 😅

If you want to try 8.0.0-dev.1 now, you need to put this to app/build.gradle or the build fails:

rootProject.ext {
  set('FlutterFire', [
    FirebaseSDKVersion: '25.12.0'
  ])
}

Not sure if that is fully safe regarding other FlutterFire plugins, but I haven't noticed new issues so far.

I can't use this plugin with v2 embedding every "solution" in this post did not work for me.

I will revert to pre v2 embedding 😢

@Ehesp are there dates when the next dev en stable release will be released?

We will release in a couple of weeks. Is that feasible?

@vanlooverenkoen In the next few days is our plan. We've just got to ensure the SDK upgrades work with everything else, and also it's the Firebase Summit this week so want to make sure there's nothing new landing which will break things :)

@vanlooverenkoen In the next few days is our plan. We've just got to ensure the SDK upgrades work with everything else, and also it's the Firebase Summit this week so want to make sure there's nothing new landing which will break things :)

@Ehesp the next few days is for a dev release? or a stable release?

Hope to see the fix soon... my clients are complaining that app is crashing whenever they receives notification :-(

Hope to see the fix soon... my clients are complaining that app is crashing whenever they receives notification :-(

Crashes can be fixed by replacing the Application with a custom one that extends FlutterApplication. If you want to receive notifications in the background. revert to pre v2 embedding

Adding

   <application
        android:name="io.flutter.app.FlutterApplication"

Fixes crashes provisionally. But that shouldn't be the final solution

android:name="io.flutter.app.FlutterApplication"

When I put the above line, it stopped crashing... I hope there will not be any side effect of it... Thanks for your time and help @ReniDelonzek

Adding

   <application
        android:name="io.flutter.app.FlutterApplication"

Fixes crashes provisionally. But that shouldn't be the final solution

I have this in my Manifest and I'm still getting crashes whenever I receive a notification....

java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set

I'm not even using the onBakgroundMessage callback.

By the way, if I remove this from the manifest it stops crashing:

            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

But of course tapping on the notifications does nothing now...

@vanlooverenkoen any idea if that fixes this? All I see is:

  • FEAT: bump firebase sdk version to 6.33.0.
  • DOCS: typos.

Not sure I will try to migrate in a couple hours. Still working on something else first.

Sorry, maybe a dumb question but I wanted to test this out ASAP so figured I would ask. I had everything working well, with firebase messages triggered my app updates etc. I had this very random crash though which led me to this thread after getting the bugreport indication about "ensureInitializationComplete must be called after startInitialization".

So I just went from version "^7.0.3" to version "8.0.0-dev2". Then I can't compile because something is deprecated I think with FirebaseMessaging. I used to have this:

FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

but then the _firebaseMessaging didn't have "configure" or "onIosSettingsRegistered" defined anymore?

I see this was deprecated to:

FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;

but I still can't compile with configure(). In the example it still uses deprecated version I had initially so I'm just at a loss I think with DART syntax I should be using. Any help would be appreciated!

You can use FirebaseMessaging.onMessage or something like that to get the old methods

Migration guide & docs will be released soon, however the dev release is good to start using (+ testing).

Aside from some local tests failing, you can find everything here: https://github.com/invertase/flutterfire/pull/76

Ok, this will take me some time to setup for migration and get the new way of using firebase setup. I'll do that but in the short term if I add the line above:

    <!-- temp change per https://github.com/FirebaseExtended/flutterfire/issues/1754 -->
    android:name="io.flutter.app.FlutterApplication"

in my AndroidManifest.xml in the I have two questions.

1) does this also solve the issue on iOS? I'm showing my Flutter lack of knowledge here, but I see this random crash on ios and android and I'm assuming they are the same (both random and frequent when app is in background). But I would also guess Android.Manifest.xml has nothing to do with my app on iOS? Is that true?

2) I thought I realized a way to trigger this background crash now. Send my app messages when it's in the background. In my Flutter app these happen based on changes to something like a slider level on the web. I move the slider in my app running as a website and that triggers FCM to update all apps for that same client that's using the web. I validate this works when in the foreground, then put my app in the background and trigger the same thing but I don't see a crash. Any idea?

@jdeltoft

  1. That has no impact on anything to do with iOS.
  2. Hard to say, the rework is a full overhaul, brand new code and implementation of FCM so hopefully your issues are fixed.

@Ehesp Has the data field been tested on iOS? After migrating to 8.0.0-dev2, my iOS notifications are now breaking when testing on iPhone X, iOS 14.1 with profile mode.. I followed the documentation, here's a code snippet.

    var initialMessage = await firebaseMessaging.getInitialMessage();

    if (initialMessage?.data['type'] == 'inbox') {
      await goToInbox();
    }

    if (initialMessage?.data['type'] == 'qna') {
      await goToQna(initialMessage?.data);
    }

    onMessage = FirebaseMessaging.onMessageOpenedApp
        .listen((RemoteMessage message) async {
      if (message.data['type'] == 'inbox') {
        await goToInbox();
      }
      if (message.data['type'] == 'qna') {
        await goToQna(message.data);
      }
    });

The previous version when I used .configure() was working perfectly for iOS.

Specifically what happens now is that I receive the notification successfully but upon tapping on it, it opens the app but crashes it immediately.

In the previous version, the data field behaved differently for iOS and Android, where in iOS the data field was missing and the data was combined into the top-level in message instead. Hence in that case I had to catch both scenarios separately.. I'm assuming the new updated plugin is doing that behind-the-scenes? I tried to catch it by casting message to a Map when data is null, but that doesn't seem to work for me either.

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.

When will this fix get to a stable branch?

Adding

   <application
        android:name="io.flutter.app.FlutterApplication"

Fixes crashes provisionally. But that shouldn't be the final solution

I have this in my Manifest and I'm still getting crashes whenever I receive a notification....

java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set

I'm not even using the onBakgroundMessage callback.

By the way, if I remove this from the manifest it stops crashing:

            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

But of course tapping on the notifications does nothing now...

New migration guide says that it'll open the app after clicking notification even after removing these

Messaging only: If you added the previous versions intent-filter to your android/app/src/main/AndroidManifest.xml file, remove it:

<intent-filter> <action android:name="FLUTTER_NOTIFICATION_CLICK" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>

doc link: https://firebase.flutter.dev/docs/migration/

We don't need to create Application.kt or include anything in AndroidManifest

Adding

   <application
        android:name="io.flutter.app.FlutterApplication"

Fixes crashes provisionally. But that shouldn't be the final solution

This one works for me.

I removed the intent-filter as specified in the migration doc, but now clicking on a notification no longer brings the user into the app.

<intent-filter> <action android:name="FLUTTER_NOTIFICATION_CLICK" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>

Was this page helpful?
0 / 5 - 0 ratings