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

报错:找不到io.flutter.plugins.firebasemessaging包该如何解决?

解决编译错误:package io.flutter.plugins.firebasemessaging does not exist

以下是针对性的解决步骤:

  • 检查并更新firebase_messaging依赖
    确保pubspec.yaml中已正确添加依赖,执行以下命令自动添加最新兼容版本:

    flutter pub add firebase_messaging
    

    之后运行flutter pub get拉取完整依赖。

  • 修正导入语句的包路径
    若使用的是较新版本的firebase_messaging,FlutterFirebaseMessagingService的包路径已变更,需将原导入语句修改为:

    import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService;
    
  • 检查Android项目配置

    1. 打开android/build.gradle,确保buildscript和allprojects的repositories中包含google()仓库:
      buildscript {
          repositories {
              google()
              mavenCentral()
          }
          dependencies {
              classpath 'com.google.gms:google-services:4.3.15' // 或最新兼容版本
          }
      }
      
      allprojects {
          repositories {
              google()
              mavenCentral()
          }
      }
      
    2. 打开android/app/build.gradle,确保末尾添加了Google服务插件:
      apply plugin: 'com.google.gms.google-services'
      
  • 清理缓存并重新构建
    执行以下命令清理项目缓存,再重新构建:

    flutter clean
    flutter pub get
    flutter run
    
  • 确认版本兼容性
    确保firebase_messaging版本与当前Flutter SDK版本兼容,若为旧项目,可尝试升级firebase_messaging到适配当前Flutter的稳定版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 20:54:58