简体   繁体   中英

java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

I am using Firebase Cloud Messaging for push notifications in a Flutter app using node.js + Typescript.

The FCM configurations for onLaunch and onResume were working fine, until I added Firebase dynamic links. Now, every time I receive a notification, the app crashes.

I have included click_action: 'FLUTTER_NOTIFICATION_CLICK' in the notification payload as well.

I do not have an Application.java file, I am using Flutter Android Embedding V2 (Flutter Version >= 1.12) and hence, no additional integration steps are required for Android .

Error:

D/AndroidRuntime(14785): Shutting down VM E/AndroidRuntime(14785): FATAL EXCEPTION: main E/AndroidRuntime(14785): Process: com.muffly, PID: 14785 E/AndroidRuntime(14785): java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set. E/AndroidRuntime(14785): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4043) E/AndroidRuntime(14785): at android.app.ActivityThread.access$1600(ActivityThread.java:229) E/AndroidRuntime(14785): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1917) E/AndroidRuntime(14785): at android.os.Handler.dispatchMessage(Handler.java:107) E/AndroidRuntime(14785): at android.os.Looper.loop(Looper.java:226) E/AndroidRuntime(14785): at android.app.ActivityThread.main(ActivityThread.java:7592) E/AndroidRuntime(14785): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(14785): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) E/AndroidRuntime(14785): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) E/AndroidRuntime(14785): Caused b y: java.lang.RuntimeException: PluginRegistrantCallback is not set. E/AndroidRuntime(14785): at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:157) E/AndroidRuntime(14785): at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:77) E/AndroidRuntime(14785): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4031) E/AndroidRuntime(14785): ... 8 more D/OOMEventManagerFK(14785): checkEventAndDumpForJE: 0 I/Process (14785): Sending signal. PID: 14785 SIG: 9

pubspec.yaml

firebase_core: ^0.5.0

firebase_auth: ^0.18.4+1

firebase_messaging: ^7.0.0-dev.15

firebase_dynamic_links: ^0.5.0+11

firebase_core: ^0.5.0

AndroidManifest.xml

            <meta-data
                android:name="com.google.firebase.messaging.default_notification_icon"
                android:resource="@mipmap/ic_launcher" />

            <meta-data
                android:name="com.google.firebase.messaging.default_notification_channel_id"
                android:value="high_importance_channel" />

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

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
                <data
                    android:scheme="https"
                    android:host="muffly.page.link" />
            </intent-filter>


Create a separated file beside MainActivity.kt and name it Application.kt and type the following code inside it.

//Don't forget to change it to your app package name!!!
package com.your.packagename

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.setPluginRegistrant

class Application : FlutterApplication(), PluginRegistrantCallback {

  override fun onCreate() {
    super.onCreate()
    setPluginRegistrant(this)

  }

  override fun registerWith(registry: PluginRegistry?) {
    FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
  }
}

Then, on your AndroidMainfest.xml add android:name=".Application" to your application tag

 <application
  ...
  android:name=".Application"

  >

Finally, add firebase-messaging to your app/build.gradle .

dependencies {
    ...
    implementation "com.google.firebase:firebase-messaging:20.1.0"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM