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.

Muhammad Faizan
  • 353
  • 4
  • 15
  • did you solve it? – iamnabink Apr 22 '20 at 05:08
  • Sadly no, i had to use older older version of this package (firebase_messaging) – Muhammad Faizan Apr 23 '20 at 06: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 Apr 23 '20 at 09:11

2 Answers2

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"));
          }
harpreet seera
  • 1,620
  • 1
  • 7
  • 15
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)
David Buck
  • 3,752
  • 35
  • 31
  • 35
Joey
  • 57
  • 2
  • 8