Q:

Firebase Cloud Messaging for Flutter - Optionally handle background messages ERROR

I wanted to add this field to my project but I got an error. 
https://pub.dev/packages/firebase_messaging#optionally-handle-background-messages
I want to use firebase notifications in my application.  I'm adding Aplication.java for this.  After adding this file, the word registry is underlined in red. 
GeneratedPluginRegistrant.registerWith(registry);
ERROR:
\live_chat\android\app\src\main\java\com\**PACKAGENAME**\**APPNAME**\Application.java:18: error: incompatible types: PluginRegistry cannot be converted to FlutterEngine
    GeneratedPluginRegistrant.registerWith(registry);
                                           ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

FAILURE: Build failed with an exception. 

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

* Try:
Run with --stacktrace option to get the stack trace.  Run with --info or --debug option to get more log output.  Run with --scan to get full insights. 

* Get more help at https://help.gradle.org

BU�LD FAILED in 3s
Finished with error: Gradle task assembleDebug failed with exit code 1

APPNAME/android/app/src/main/java/app-organization-path/Application.java :
package **PACKAGENAME**;

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

A:

Please make sure you are do this : 
1 - Application.java class to your app in the same directory as your MainActivity.java. 
2- name property of application(same your package) in AndroidManifest.xml
<application android:name=". Application">

3- and for resloved FlutterFirebaseMessagingService i faced this problem before,  add last version of firebase-messaging in your android app build gradle file inside dependencies  
implementation 'com.google.firebase:firebase-messaging:20.1.0'

then sync android project and try build flutter app 

