我正在尝试在我的flutter应用程序中实现firebase_messaging。在 Android集成上,当我编写本机应用程序级别的代码时遇到错误。
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;
class Application: FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
GeneratedPluginRegistrant.registerWith(registry)
}
}
未解决的参考:FlutterFirebaseMessagingService
TypeMismatch:必需 FlutterEngine 。找到 PluginRegistry?
我已经在我的app文件夹下成功添加了Google-services.json,还在当前我正在使用的项目级gradle和应用级gradle中添加了所需的依赖项
实施'com.google.firebase:firebase-messaging:20.1.3'
版本。
颤振详细信息: Flutter(通道稳定,v1.12.13 + hotfix.8,在Mac OS X 10.15.1 19B88上,语言环境为en-US) Firebase_messaging版本为^ 6.0.12
我什至试图降级Firebase-Messaging的版本,但仍然发现此问题。
答案 0 :(得分:4)
在Application.kt类中只需修改函数:
override fun registerWith(registry: PluginRegistry?) {
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
答案 1 :(得分:0)
在应用程序的GeneratedPluginRegistrant.registerWith(registry)
中剪切方法registerWith;
并将其粘贴到您的MainActivity
的方法configureFlutterEngine
中,如下所示:
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
PS: 我收到了一个新的未处理异常(不影响FCM功能,但是看起来很丑;我正在研究它):
MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background)