Flutterfire: [<firebase messaging>]MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background)

Created on 22 Mar 2020  Â·  9Comments  Â·  Source: FirebaseExtended/flutterfire

I follow firebase_messaging's doc but I get this error after each notification arrive:

E/flutter (24327): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background)
E/flutter (24327): #0      MethodChannel.invokeMethod 
package:flutter/…/services/platform_channel.dart:319
E/flutter (24327): <asynchronous suspension>
E/flutter (24327): #1      _fcmSetupBackgroundChannel 
package:firebase_messaging/firebase_messaging.dart:50
E/flutter (24327): #2      _AsyncAwaitCompleter.start  (dart:async-patch/async_patch.dart:45:6)
E/flutter (24327): #3      _fcmSetupBackgroundChannel 
package:firebase_messaging/firebase_messaging.dart:23
E/flutter (24327): #4      _runMainZoned.<anonymous closure>.<anonymous closure>  (dart:ui/hooks.dart:239:25)
E/flutter (24327): #5      _rootRun  (dart:async/zone.dart:1126:13)

My flutter doctor -v:

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Linux, locale en_US.UTF-8)
    • Flutter version 1.12.13+hotfix.8 at /home/hamidreza/flutter/flutter
    • Framework revision 0b8abb4724 (6 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /home/hamidreza/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[!] Android Studio (version 3.6)
    • Android Studio at /opt/android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Connected device (1 available)
    • C6603 • CB5A1VRUQV • android-arm • Android 5.1.1 (API 22)

! Doctor found issues in 1 category.

And my MainActivity.kt:

package com.example.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);
    }
}

My Application.kt:

package com.example.app

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

class Application : FlutterApplication(), PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this)
    }

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

Most helpful comment

@marwfair this works for who create android part with java, My app is kotlin base.
I don't have src/main/com/example/app folder
but I have src/main/kotlin/com/example/app folder.

@Hamidrezana My project is Kotlin based too. Here are what my files look like:

Application.kt

package com.your.app

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

class Application : FlutterApplication(), PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this)
    }

    override fun registerWith(registry: PluginRegistry?) {
        FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
    }
}

FirebaseCloudMessagingPluginRegistrant.kt

package com.your.app

import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin

object FirebaseCloudMessagingPluginRegistrant {
    fun registerWith(registry: PluginRegistry?) {
        if (alreadyRegisteredWith(registry)) {
            return
        }
        FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
    }

    private fun alreadyRegisteredWith(registry: PluginRegistry?): Boolean {
        val key: String? = FirebaseCloudMessagingPluginRegistrant::class.java.canonicalName
        if (registry?.hasPlugin(key)!!) {
            return true
        }
        registry.registrarFor(key)
        return false
    }
}

MainActivity.kt

package com.your.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() {}

All 9 comments

Have the same issue

I'm having the same issue as well. Any solutions?

Same issue, is anyone knows the problem? I followed the docs 1:1

@marwfair this works for who create android part with java, My app is kotlin base.
I don't have src/main/com/example/app folder
but I have src/main/kotlin/com/example/app folder.

@marwfair this works for who create android part with java, My app is kotlin base.
I don't have src/main/com/example/app folder
but I have src/main/kotlin/com/example/app folder.

@Hamidrezana My project is Kotlin based too. Here are what my files look like:

Application.kt

package com.your.app

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

class Application : FlutterApplication(), PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this)
    }

    override fun registerWith(registry: PluginRegistry?) {
        FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
    }
}

FirebaseCloudMessagingPluginRegistrant.kt

package com.your.app

import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin

object FirebaseCloudMessagingPluginRegistrant {
    fun registerWith(registry: PluginRegistry?) {
        if (alreadyRegisteredWith(registry)) {
            return
        }
        FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
    }

    private fun alreadyRegisteredWith(registry: PluginRegistry?): Boolean {
        val key: String? = FirebaseCloudMessagingPluginRegistrant::class.java.canonicalName
        if (registry?.hasPlugin(key)!!) {
            return true
        }
        registry.registrarFor(key)
        return false
    }
}

MainActivity.kt

package com.your.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() {}

@marwfair thank you.
Doc doesn't say anything about FirebaseCloudMessagingPluginRegistrant.kt file, at least I didn't see anything.
now It doesn't throw any exception.

@marwfair this works for who create android part with java, My app is kotlin base.
I don't have src/main/com/example/app folder
but I have src/main/kotlin/com/example/app folder.

@Hamidrezana My project is Kotlin based too. Here are what my files look like:

Application.kt

package com.your.app

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

class Application : FlutterApplication(), PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this)
    }

    override fun registerWith(registry: PluginRegistry?) {
        FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
    }
}

FirebaseCloudMessagingPluginRegistrant.kt

package com.your.app

import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin

object FirebaseCloudMessagingPluginRegistrant {
    fun registerWith(registry: PluginRegistry?) {
        if (alreadyRegisteredWith(registry)) {
            return
        }
        FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
    }

    private fun alreadyRegisteredWith(registry: PluginRegistry?): Boolean {
        val key: String? = FirebaseCloudMessagingPluginRegistrant::class.java.canonicalName
        if (registry?.hasPlugin(key)!!) {
            return true
        }
        registry.registrarFor(key)
        return false
    }
}

MainActivity.kt

package com.your.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() {}

@marwfair
In my current app I need the FlutterActivity to handle sharing intents.
So with your lines I get the message, but don't get the information of the share anymore.
Also I can't click on the notification, which should open the app.

I've tried to combine your solution with the instructions from the docs to share intents: https://flutter.dev/docs/get-started/flutter-for/android-devs#how-do-i-handle-incoming-intents-from-external-applications-in-flutter

Now I do get a notification, when the app is in background, but still can't click the message.
Last output of console:
W/FirebaseMessaging(14833): No activity found to launch app

Unfortunately I'm not able to receive my shared text anymore.

Do you have any idea if it's even possible to ingetrate both sharing intents and fcm with flutter?
Since I searched the web for 2 days and only try/error, I'm pretty frustrated.

@marwfair this works for who create android part with java, My app is kotlin base.
I don't have src/main/com/example/app folder
but I have src/main/kotlin/com/example/app folder.

it does't matter if you user src/main/kotlin/com/example/app folder instread of src/main/com/example/app folder.

Was this page helpful?
0 / 5 - 0 ratings