You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter接入FCM后添加Firebase动态链接点击通知崩溃问题求助

崩溃触发原因

报错栈中java.lang.IllegalArgumentException: Unsupported value: Bundle[mParcelledData.dataSize=100]是核心问题,触发原因有两个:

  • 你当前使用的firebase_messaging: ^7.0.0-dev.15是未稳定的开发版本,没有对Android原生Bundle类型数据做Flutter层序列化适配,Flutter默认的StandardMessageCodec不支持直接传递原生Bundle对象,当Intent携带复杂数据时就会抛出序列化异常。
  • 接入Firebase Dynamic Links后,两个插件都会监听Activity的onNewIntent事件,点击推送通知触发的Intent会同时携带FCM通知数据和动态链接相关的Bundle数据,FCM插件尝试把所有Intent数据全部序列化传递到Flutter层时,未处理的Bundle对象就会触发崩溃。

报错中的Missing Default Notification Channel为警告,你已经在AndroidManifest中配置了对应参数,只需启动时提前创建ID为high_importance_channel的通知通道即可消除,不是崩溃的触发原因。

解决方案

按以下步骤操作即可修复:

1. 升级依赖到兼容稳定版本

首先替换pubspec.yaml中的Firebase相关依赖,选择版本对齐的稳定组合,修复插件间的原生逻辑冲突:

方案A:适配新版Firebase(推荐)

firebase_core: ^1.24.0
firebase_auth: ^3.11.2
firebase_messaging: ^14.6.1
firebase_dynamic_links: ^4.3.5

升级后建议通过flutterfire configure命令自动匹配各平台原生SDK版本,避免版本不一致问题。

方案B:低版本兼容(无需大幅修改业务代码)

如果不想调整现有FCM、动态链接的业务逻辑,可使用以下低版本稳定组合:

firebase_core: ^0.7.0
firebase_auth: ^0.20.1
firebase_messaging: ^8.0.0-dev.15
firebase_dynamic_links: ^0.6.0

2. 调整AndroidManifest.xml配置

将FCM和动态链接的Intent-filter分开配置,避免Intent匹配逻辑冲突:

<!-- 原有FCM通知点击配置保留 -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@mipmap/ic_launcher" />
<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="high_importance_channel" />
<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>

<!-- 新增动态链接专属Intent-filter,不要和FCM配置合并 -->
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <!-- 替换为你自己的动态链接域名 -->
    <data
        android:host="xxx.page.link"
        android:scheme="https"/>
</intent-filter>

3. 调整推送通知Payload结构

服务端发送推送时,将动态链接地址放在data字段中传递,不要放在notification字段中,避免原生层自动封装为未适配的Bundle对象:

{
  "token": "用户设备FCM令牌",
  "data": {
    "dynamic_link": "你的动态链接完整地址",
    "notify_type": "跳转动态链接"
  },
  "notification": {
    "title": "通知标题",
    "body": "通知内容"
  }
}

4. 调整Flutter层接收逻辑

在FCM的onMessage、onLaunch、onResume回调中,先读取data字段中的动态链接参数,再交给firebase_dynamic_links插件处理跳转,不要让FCM插件直接处理链接路由。

内容的提问来源于stack exchange,提问作者Prajeet Mehra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 20:27:03