如何在接收基于Flutter构建的FCM推送通知时修复应用程序崩溃 [英] How to fix app crash on recieving FCM Push Notification built on Flutter

查看:203
本文介绍了如何在接收基于Flutter构建的FCM推送通知时修复应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Flutter上构建了一个应用,并试图通过FCM发送推送通知.之前它可以正常工作,但是在更改Firebase消息传递的版本后,一旦我发送了推送通知,该应用就会崩溃.

I have built an app on Flutter and was trying to send Push Notifications through FCM. Earlier it was working but after changing the version of Firebase messaging the app crashes as soon as I send a push notification.

我尚未对《守则》进行任何更改.我调查了GitHub问题,但无法解决.

I haven't made any changes in the Code per se. I looked into the GitHub issues but couldn't resolve it.

这是我在main.dart文件中一直使用的代码.

This is the code I have been using in the main.dart file.

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

  void initState() {
    super.initState();

    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) {
        print('on message $message');
      },
      onResume: (Map<String, dynamic> message) {
        print('on resume $message');
      },
      onLaunch: (Map<String, dynamic> message) {
        print('on launch $message');
      },
    );
    _firebaseMessaging.requestNotificationPermissions(
        const IosNotificationSettings(sound: true, badge: true, alert: true));
    _firebaseMessaging.getToken().then((token){
      print(token);
    });

我的firebase_messaging依赖项

My firebase_messaging dependency

  firebase_messaging: ^1.0.2

我还更改了app/build.gradle中的google-services版本

I had also changed the version of google-services in app/build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.2.0'
    }

这是添加到AndroidManifest.xml文件中以进行通知的部分

This is the part added to the AndroidManifest.xml file for notifications

 <intent-filter>
     <action android:name="FLUTTER_NOTIFICATION_CLICK" />
     <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>

设备日志

03-24 19:14:25.044 2630 2663 I Activity Manager:启动proc 17709:com.example.notif_app/u0a206广播com.example.notif_app/com.google.firebase.iid.FirebaseInstanceIdReceiver03-24 19:14:25.047 17709 17709我的艺术:后期启用-Xcheck:jni03月24日19:14:25.181 17709 17709 D FirebaseApp:com.google.firebase.auth.FirebaseAuth未链接.跳过初始化.03月24日19:14:25.182 17709 17709 D FirebaseApp:com.google.firebase.crash.FirebaseCrash未链接.跳过初始化.03月24日19:14:25.182 17709 17709 I FirebaseInitProvider:FirebaseApp初始化成功03-24 19:14:25.199 17709 17730 I ResourceExtractor:找到提取的资源res_timestamp-1-155343182858703-24 19:14:25.206 17709 17727 I FA:正在启动应用程序测量,版本:1530003-24 19:14:25.206 17709 17727 I FA:要启用调试日志记录,请运行:adb shell setprop log.tag.FA VERBOSE03-24 19:14:25.207 17709 17727 I FA:要启用更快的调试模式事件记录,请运行:03-24 19:14:25.207 17709 17727 I FA:adb shell setprop debug.firebase.analytics.app com.example.notif_app03-24 19:14:25.220 17709 17709 D AndroidRuntime:关闭VM03-24 19:14:25.221 17709 17709 E AndroidRuntime:致命异常:main03-24 19:14:25.221 17709 17709 E AndroidRuntime:进程:com.example.notif_app,PID:1770903月24日19:14:25.221 17709 17709 E AndroidRuntime:java.lang.NoSuchMethodError:无静态方法zzad()Lcom/google/firebase/iid/zzan;在Lcom/google/firebase/iid/zzan类中;或其上级类("com.google.firebase.iid.zzan"的声明出现在/data/app/com.example.notif_app-1/base.apk:classes2.dex中)03月24日19:14:25.221 17709 17709 E AndroidRuntime:com.google.firebase.messaging.FirebaseMessagingService.zzb(未知源)03月24日19:14:25.221 17709 17709 E AndroidRuntime:在com.google.firebase.iid.zzb.onStartCommand(未知来源)03月24日19:14:25.221 17709 17709 E AndroidRuntime:位于android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3318)03月24日19:14:25.221 17709 17709 E AndroidRuntime:位于android.app.ActivityThread.-wrap21(ActivityThread.java)

有人可以帮我吗?预先感谢.

Can anyone help me with this? Thanks in advance.

推荐答案

打开android项目.

Open the android project.

进入firebase_messaging的build.gradle

Go the build.gradle of firebase_messaging

在依赖项中,将 api'com.google.firebase:firebase-messaging:18.0.0'更改为 api'com.google.firebase:firebase-messaging:17.3.3'

In the dependencies change api 'com.google.firebase:firebase-messaging:18.0.0' to api 'com.google.firebase:firebase-messaging:17.3.3'

确保您使用的是pubspec.yaml中所有云依赖项的最新版本

Make sure you are using the latest version of all the cloud dependencies in pubspec.yaml

此解决方案对我有用

这篇关于如何在接收基于Flutter构建的FCM推送通知时修复应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆