gpt4 book ai didi

firebase - PluginRegistry无法转换为FlutterEngine

转载 作者:行者123 更新时间:2023-12-01 17:58:46 25 4
gpt4 key购买 nike

当我将 flutter 更新到版本 1.12.13 时,我发现了这个问题并且无法修复它。我按照发送的 firebase_messaging 教程进行操作并收到以下错误:“错误:类型不兼容:PluginRegistry 无法转换为 FlutterEngine generatedPluginRegistrant.registerWith(注册表); ”我的代码如下:

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;

关于firebase - PluginRegistry无法转换为FlutterEngine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59446933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com