Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_messaging] Type mismatch: inferred type is PluginRegistry? but FlutterEngine was expected #1613

Closed
Jacobsjj2 opened this issue Dec 12, 2019 · 11 comments
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: bug Something isn't working

Comments

@Jacobsjj2
Copy link

Following the instructions on pub.dev for handling background messages doesn't compile for Android since the GeneratedPluginRegistrant.registerWith method takes a FlutterEngine object as a parameter. Using the PluginRegistry provided by the method throws the error

Type mismatch: inferred type is PluginRegistry? but FlutterEngine was expected

Please see the below code for reference

package ...

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) //Error thrown here
    }
}

To reproduce
Steps to reproduce the behavior:

  1. Follow the steps in the given link up to step 1 of Optionally handle background messages
  2. Build the project

Expected behavior
Somehow a FlutterEngine object should be passed to the method in order to successfully build for Android

@Jacobsjj2 Jacobsjj2 added the type: bug Something isn't working label Dec 12, 2019
@hsangtini
Copy link

Fixed by replace with:

class MainApplication : FlutterApplication(), PluginRegistrantCallback {

    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

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

}

@iapicca
Copy link

iapicca commented Dec 12, 2019

Hi @Jacobsjj2
does the solution proposed by @hsangtini work for you?
thank you

@iapicca iapicca added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Dec 12, 2019
@Jacobsjj2
Copy link
Author

This does allow me to compile, but I'm not sure if the background service is being registered correctly since I get the error

E/flutter (12123): [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 (12123): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7)
E/flutter (12123): <asynchronous suspension>
E/flutter (12123): #1      _fcmSetupBackgroundChannel (package:firebase_messaging/firebase_messaging.dart:51:21)
E/flutter (12123): #2      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45:6)
E/flutter (12123): #3      _fcmSetupBackgroundChannel (package:firebase_messaging/firebase_messaging.dart:24:32)
E/flutter (12123): #4      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:239:25)
E/flutter (12123): #5      _rootRun (dart:async/zone.dart:1126:13)
E/flutter (12123): #6      _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (12123): #7      _runZoned (dart:async/zone.dart:1518:10)
E/flutter (12123): #8      runZoned (dart:async/zone.dart:1502:12)
E/flutter (12123): #9      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:231:5)
E/flutter (12123): #10     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)
E/flutter (12123): #11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

Doesn't the replacement simply return a Registrar object without registering anything?

@hsangtini
Copy link

This does allow me to compile, but I'm not sure if the background service is being registered correctly since I get the error

E/flutter (12123): [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 (12123): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7)
E/flutter (12123): <asynchronous suspension>
E/flutter (12123): #1      _fcmSetupBackgroundChannel (package:firebase_messaging/firebase_messaging.dart:51:21)
E/flutter (12123): #2      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45:6)
E/flutter (12123): #3      _fcmSetupBackgroundChannel (package:firebase_messaging/firebase_messaging.dart:24:32)
E/flutter (12123): #4      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:239:25)
E/flutter (12123): #5      _rootRun (dart:async/zone.dart:1126:13)
E/flutter (12123): #6      _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (12123): #7      _runZoned (dart:async/zone.dart:1518:10)
E/flutter (12123): #8      runZoned (dart:async/zone.dart:1502:12)
E/flutter (12123): #9      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:231:5)
E/flutter (12123): #10     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)
E/flutter (12123): #11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

Doesn't the replacement simply return a Registrar object without registering anything?

Try this replace @Jacobsjj2

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

@Jacobsjj2
Copy link
Author

Sorry for the delay! @hsangtini's latest suggestion works. I guess it would also be necessary to update the documentation to that then?

@jayvhaile
Copy link

I tried your solution and i am getting

Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService, unresolved supertypes: com.google.firebase.messaging.FirebaseMessagingService

@isyantoID
Copy link

Fixed by replace with:

class MainApplication : FlutterApplication(), PluginRegistrantCallback {

    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

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

}

tq work for me

@iapicca iapicca added impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Feb 12, 2020
@insinfo
Copy link

insinfo commented Aug 10, 2020

I also had this problem, I changed the "Application.kt" to the suggested one. and now it's compiling, I just haven't tested the notifications yet.

Application.kt

package br.gov.rj.riodasostras.riodasostrasapp

import android.os.Bundle

import io.flutter.app.FlutterActivity
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
//import com.google.firebase.messaging.FirebaseMessagingService

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

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

MainActivity.kt

package br.gov.rj.riodasostras.riodasostrasapp

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

flutter doctor

 flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.20.1, on Microsoft Windows [versão 10.0.18362.657], locale pt-BR)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[√] Android Studio (version 3.6)
[√] IntelliJ IDEA Community Edition (version 2019.3)
[√] VS Code (version 1.45.1)
[√] Connected device (1 available)

• No issues found!
PS D:\MyDartProjects\riodasostrasapp> flutter doctor -v
[√] Flutter (Channel stable, 1.20.1, on Microsoft Windows [versão 10.0.18362.657], locale pt-BR)
    • Flutter version 1.20.1 at C:\src\flutter
    • Framework revision 2ae34518b8 (5 days ago), 2020-08-05 19:53:19 -0700
    • Engine revision c8e3b94853
    • Dart version 2.9.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
    • Android SDK at C:\Users\isaque\AppData\Local\Android\sdk
    • Platform android-R, build-tools 29.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] IntelliJ IDEA Community Edition (version 2019.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4
    • Flutter plugin version 45.0.2
    • Dart plugin version 193.6911.31

[√] VS Code (version 1.45.1)
    • VS Code at C:\Users\isaque\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.12.2

[√] Connected device (1 available)
    • SM J120H (mobile) • 4200b9bf90139200 • android-arm • Android 5.1.1 (API 22)

• No issues found!

Ideally, the Readme and documentation should be updated

@yourshinsuke
Copy link

yourshinsuke commented Aug 24, 2020

android/app/src/main/kotlin/com/example/my_app/Aplication.kt

package com.example.my_app

import android.os.Bundle

import io.flutter.app.FlutterActivity
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
//import com.google.firebase.messaging.FirebaseMessagingService

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

  override fun registerWith( registry: PluginRegistry) {
    GeneratedPluginRegistrant.registerWith(registry);
  }
}

@yourshinsuke
Copy link

@insinfo
Hello
You mean.
rename Application.kt to MainActivity.kt?
How is your android/app/src/main/AndroidManifest.xml?

Do you import? both of them?

        <activity
            android:name=".MainActivity"
// something

        <activity
            android:name=".Application"
        />

@Salakar
Copy link
Member

Salakar commented Nov 5, 2020

Hey all 👋

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues. Additionally, messaging now supports v2 embedding.

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone.

@Salakar Salakar closed this as completed Nov 5, 2020
@firebase firebase locked and limited conversation to collaborators Dec 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) plugin: messaging type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants