firebase - PluginRegistry cannot be converted to FlutterEngine
问题描述
As soon as I updated the flutter to version 1.12.13 I found this issue and can't fix it. I did as the firebase_messaging tutorial sent and got the following error: "error: incompatible types: PluginRegistry cannot be converted to FlutterEngine GeneratedPluginRegistrant.registerWith (registry); " My code is as follows:
package io.flutter.plugins;
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 android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel("messages","Messages", NotificationManager.IMPORTANCE_LOW);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
解决方案
替换此代码行:
GeneratedPluginRegistrant.registerWith(registry);
有了这个:
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
确保导入:
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
推荐阅读
- javascript - 使用 Isotope.js 和 React 创建一个带过滤器的砌体布局?
- scala - 如何将容器中的动态暴露端口传递给我的应用程序?
- java - 展平地图中的列表列表
- python - 如何将多个列表写入 csv 文件?
- java - javax.mail:不拾取属性
- facebook - 完全访问 Facebook 图形 API 的最低要求?
- android - 创建 L2TP/IPSec 客户端 android
- hibernate - 在关系表中自动填充数据
- python - BeautifulSoup 在网络抓取亚马逊时无法正常工作
- c++ - 有没有办法从文本文件中读取并将单个数据存储为不同的变量?