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? 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 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"));
          }
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @harpeetSeera for the answer. Needed to know is this a kotlin issue, or this library issue??
it's neither kotlin issue nor library issue, it's just that we need to register the plugin to use it.
what about firebase_messaging: "^9.0.0"? It's now changed
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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.