颤振:FlutterFcmService - 致命:找不到回调
Posted
技术标签:
【中文标题】颤振:FlutterFcmService - 致命:找不到回调【英文标题】:flutter: FlutterFcmService - Fatal: failed to find callback 【发布时间】:2020-12-08 18:05:34 【问题描述】:我想在我的颤振应用程序上使用 fcm,所以在创建 firebase 控制台并在我的 gradle 中安装一些依赖项后,如下所示:
build.gradle: 项目
dependencies
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
build.gradle: 应用程序
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
...
dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
并创建一个 Java Application 类:
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.FirebaseMessagingPlugin;
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)
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
并在清单中添加此应用程序类和意图过滤器:
<application
android:name=".Application"
android:label="sian_mobile"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
...
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
并在 pubspect 中安装 firebase_messaging: ^7.0.0
我编写了这个简单的 FirebaseMessaging 代码:
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
@override
void initState()
super.initState();
_firebaseMessaging.configure(
onMessage: (message) async
print("-------> $message");
,
onResume: (message) async
print("-------> $message");
,
onLaunch: (message) async ,
);
当我运行应用程序并且应用程序在前台时,我将通知从控制台推送到应用程序。在 vscode 控制台中我得到了这个错误:
Installing build/app/outputs/flutter-apk/app.apk...
E/FlutterFcmService(11005): Fatal: failed to find callback
Connecting to VM Service at ws://127.0.0.1:41113/PSCQfaDH4oA=/ws
D/EGL_emulation(11005): eglMakeCurrent: 0xe83ba420: ver 2 0 (tinfo 0xc80dd6e0)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->size()I (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->get(I)I (greylist, reflection, allowed)
W/.ian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (greylist, reflection, allowed)
I/flutter (11005): -------> notification: title: test title, body: Test notification text, data:
【问题讨论】:
试试这个。@Override public void registerWith(PluginRegistry registry) GeneratedPluginRegistrant.registerWith(registry);
而不是你的
我收到演员警告:pasteboard.co/Jn613xj.png@ShriHari
您找到解决方案了吗?
不,我仍然遇到这些错误。但是我收到了推送消息。 @Mobile_Dev
同样的事情发生在我身上,我做了这个并让它在 Android 上工作:1)从清单中删除了 当应用程序在前台时,似乎仍然收到推送消息。该问题可能是由于应用程序在后台时没有推送消息的处理程序引起的。我建议通过guide 设置后台消息处理程序。
【讨论】:
以上是关于颤振:FlutterFcmService - 致命:找不到回调的主要内容,如果未能解决你的问题,请参考以下文章
FlutterFcmService("number"): Fatal: 找不到回调