Describe the bug
Currently the documentation does NOT support the new Flutter Android v2 embedding that came along with flutter 1.12.13. The function GeneratedPluginRegistrant.registerWith(registry); no longer accepts a io.flutter.plugin.common.PluginRegistry object, but a io.flutter.embedding.engine.FlutterEngine object.
Current code in documentation:
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;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
Newer code attempt with error:
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry); // ERROR: Expects io.flutter.embedding.engine.FlutterEngine
}
}
To Reproduce
Steps to reproduce the behavior:
flutter create -a java exampleany solution for this error?
same issue
Solved it with following:
app/src/build.gradle
add the following:
implementation "com.google.firebase:firebase-messaging:20.1.0"
Application.kt
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin");
}
}
That would be better to get an official fix and not have to do a workaround with potential side effect
I have another issue with the @gakubhat workaround (https://github.com/FirebaseExtended/flutterfire/issues/116)
I followed this workaround : https://www.djamware.com/post/5e4b26e26cdeb308204b427f/flutter-tutorial-firebase-cloud-messaging-fcm-push-notification
Frustrating to have so many issues on a important plugin...
@Ehesp hi, is there any ETA for solving this?
This issue has been opened about half a year ago and still not under real investigation? C'mon guys, this is a real show stopper, especially for newbies that want to get into this stuff...
Just set up a new, standard flutter project and follow the current documentation. It won't work...
@All Sorry about the delay here, we are currently working on updating the messaging plugin, the documentation will be updated according to those final updates. We should have more on this very soon.
脡 s贸 voc锚 usar o PluginRegistry.PluginRegistrantCallback dessa forma:
class FirebaseCloudMessagingPluginRegistrant {
companion object {
fun registerWith(registry: PluginRegistry) {
if (alreadyRegisteredWith(registry)) {
return;
}
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
}
fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
val key = FirebaseCloudMessagingPluginRegistrant::class.java.name
if (registry.hasPlugin(key)) {
return true
}
registry.registrarFor(key)
return false
}
}
}
class MainActivity : FlutterActivity(), PluginRegistry.PluginRegistrantCallback {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
override fun registerWith(registry: PluginRegistry?) {
registry?.let { FirebaseCloudMessagingPluginRegistrant.registerWith(it) }
}
}
Funciona normalmente o "backgroundMessage handler" no meu projeto j谩 modificado para embedding V2.
I'm a bit confused about which plugins need to be manually registered in the registerWith method.
Is it any plugin that we are using in the background, or is it plugins that haven't yet updated to the v2 embedding?
Has this issue be resolved now, anybody knows? It is really important plugin for the Flutter framework.
It will be resolved "very very soon", when version 8.0.0 will be released.
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. Specifically v2 embedding is now supported and requires no documentation/manual steps unless you still need to use v1 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.
Most helpful comment
Solved it with following:
app/src/build.gradleadd the following:
implementation "com.google.firebase:firebase-messaging:20.1.0"Application.kt