4

I am trying to implement firebase_messaging in my flutter application. On Android Integration when i write native Application level code i get errors.

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?) {
        GeneratedPluginRegistrant.registerWith(registry)
    }
}

Unresolved Reference: FlutterFirebaseMessagingService

TypeMismatch: Required FlutterEngine. Found PluginRegistry?

I have successfully added Google-services.json under my app folder also added the required dependencies in the project level gradle and app level gradle currently i am using

implementation 'com.google.firebase:firebase-messaging:20.1.3'

Version.

Flutter Details: Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.1 19B88, locale en-US) Firebase_messaging version is ^6.0.12

I have even tried to downgrade the version of firebase-Messaging but still found this problem.

3
  • did you solve it?
    – iamnabink
    Commented Apr 22, 2020 at 5:08
  • Sadly no, i had to use older older version of this package (firebase_messaging) Commented Apr 23, 2020 at 6:04
  • ok, but you could have replace your registerWith() function with following code: override fun registerWith(registry: PluginRegistry?) { registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"); } This should have solve your problem
    – iamnabink
    Commented Apr 23, 2020 at 9:11

2 Answers 2

6

in your Application.kt class just modify the function:

 override fun registerWith(registry: PluginRegistry?) {
        io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
          }
3
  • Thanks @harpeetSeera for the answer. Needed to know is this a kotlin issue, or this library issue?? Commented Jul 1, 2020 at 18:24
  • it's neither kotlin issue nor library issue, it's just that we need to register the plugin to use it. Commented Jul 2, 2020 at 6:22
  • what about firebase_messaging: "^9.0.0"? It's now changed Commented Mar 9, 2021 at 11:03
0

Cut method GeneratedPluginRegistrant.registerWith(registry) in your Application's registerWith; and paste it into your MainActivity's method configureFlutterEngine, like this :

public class MainActivity extends FlutterActivity {
    @Override
    public void configureFlutterEngine(FlutterEngine flutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);

    }
}

PS: I got a new Unhandled Exception (doesn't affect FCM function, but looks ugly; I'm working on it):

MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background)

Not the answer you're looking for? Browse other questions tagged or ask your own question.