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

Firebase通知集成遇Host Object::get未知异常求助

解决Firebase通知集成中的Exception in Host Object::get: <unknown>错误

我之前也踩过这个模糊错误的坑,给你几个针对性的排查和解决方向:

  • 检查Firebase配置文件的有效性
    确认你用的google-services.json(Android)或GoogleService-Info.plist(iOS)是从Firebase控制台最新下载的,里面的project_id、messagingSenderId、api_key等核心字段没有缺失或错误。如果是跨平台框架(比如Flutter、React Native),还要确保配置文件放在了正确的项目目录下——Android要放在android/app,iOS放在ios/Runner。

  • 统一Firebase依赖版本
    Firebase各模块的版本不匹配是触发这类底层错误的常见原因。比如Android的build.gradle里,所有Firebase相关依赖尽量使用相同的大版本:

    implementation 'com.google.firebase:firebase-messaging:23.4.0'
    implementation 'com.google.firebase:firebase-core:21.1.1'
    implementation 'com.google.firebase:firebase-auth:22.3.1'
    

    可以去Firebase官网查最新的兼容版本列表,避免版本差异过大。

  • 清理项目缓存并彻底重建
    缓存问题经常会导致莫名其妙的异常,试试这些操作:

    • Android:在项目根目录执行./gradlew clean,然后重新构建
    • iOS:删除Pods文件夹,执行pod install,再用Xcode的Cmd+Shift+K清理缓存后重建
    • Flutter/React Native:执行框架自带的清理命令(比如flutter clean),重新拉取依赖后重启IDE再构建
  • 验证通知权限申请逻辑
    确认你在应用启动时正确申请了通知权限:

    • Android 13+需要主动申请POST_NOTIFICATIONS权限
    • iOS必须请求用户授权通知权限
      以Flutter为例,用firebase_messaging的权限申请代码要确保执行到位:
    NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(
      alert: true,
      badge: true,
      sound: true,
    );
    
  • 排查Android通知通道配置
    Android 8.0及以上必须创建通知通道,如果通道的ID为空、名称/描述不合法,或者创建逻辑有误,也可能触发这类Host Object错误。检查你的通道创建代码是否正确:

    val channel = NotificationChannel(
      "your_unique_channel_id",
      "App Notification Channel",
      NotificationManager.IMPORTANCE_HIGH
    ).apply {
      description = "Receive notifications from the app"
    }
    val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    notificationManager.createNotificationChannel(channel)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 05:08:05