Introduction
Are you facing the perplexing error “PluginRegistry cannot be converted to FlutterEngine” after updating your Flutter version to 1.12.13? This error often occurs when working with Firebase Cloud Messaging (FCM) and can prevent your code from running properly. In this blog post, we will explore the causes of this error and provide step-by-step solutions to help you resolve it. Let’s dive in and fix this issue together!
Understanding the Error
When you update Flutter to version 1.12.13 and follow the Firebase Messaging tutorial, you may encounter the error message “error: incompatible types: PluginRegistry cannot be converted to FlutterEngine GeneratedPluginRegistrant.registerWith(registry);” This error typically arises due to changes in the plugin registration process and requires adjustment in your code.
Solution: Updating Plugin Registration
To resolve the “PluginRegistry cannot be converted to FlutterEngine” error, follow these steps:
- Open the file
Application.java
in your Android project. - Locate the method
registerWith(PluginRegistry registry)
and replace the lineGeneratedPluginRegistrant.registerWith(registry);
with the following code:
codeFirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
- Ensure that you have imported the necessary classes:
codeimport io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
- Save the file and rebuild your project.
Alternative Solution for Kotlin
If you’re using Kotlin for your Flutter project, follow these steps to resolve the error:
- Open the file
Application.kt
in your Android project. - Locate the method
registerWith(registry: PluginRegistry)
and replace the lineFirebaseCloudMessagingPlugin.registerWith(registry);
with the following code:
codeFirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
- Ensure that you have imported the necessary classes:
codeimport io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
- Save the file and rebuild your project.
Conclusion
By following the steps outlined above, you should be able to resolve the “PluginRegistry cannot be converted to FlutterEngine” error and ensure smooth integration of Firebase Cloud Messaging in your Flutter project. Remember to update the plugin registration code in the appropriate file based on your project’s language (Java or Kotlin).