Muhammad Faizan
Muhammad Faizan

Reputation: 373

Flutter Firebase Notification issue Android

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.

Upvotes: 4

Views: 4108

Answers (2)

Joey
Joey

Reputation: 57

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)

Upvotes: 0

harpreet seera
harpreet seera

Reputation: 1828

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"));
          }

Upvotes: 6

Related Questions