Solvedflutterfire [firebase_messaging] No documentation for Android v2 embedding backgroundMessage handler

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:

  1. Run flutter create -a java example
  2. Follow firebase_messaging background messaging instructions
  3. Notice GeneratedPluginRegistrant.registerWith(registry) no longer expects a PluginRegistry type
14 Answers

βœ”οΈAccepted Answer

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


}

Other Answers:

That would be better to get an official fix and not have to do a workaround with potential side effect

@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.

More Issues: