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

Flutter项目Xcode构建失败:提示No such module 'Flutter'及Firebase错误

解决Flutter iOS构建中"No such module 'Firebase'"的问题

1. 确认Firebase依赖配置

  • 检查项目根目录的pubspec.yaml,确保已添加Firebase核心依赖及所需服务插件,示例:
    dependencies:
      flutter:
        sdk: flutter
      firebase_core: ^2.24.2 # 版本号以最新兼容版为准
      # 按需添加其他Firebase插件,如firebase_auth、firebase_firestore等
    
  • 执行flutter pub get拉取最新依赖。

2. 验证Firebase配置文件

  • 确认ios/Runner目录下存在GoogleService-Info.plist(从Firebase控制台下载的对应项目配置文件)。
  • 在Xcode中选中该文件,右侧Inspector面板的Target Membership需勾选Runner。

3. 修复Podfile配置

  • 打开ios/Podfile,确保配置符合要求:
    platform :ios, '13.0' # 最低版本不低于13.0,适配Firebase要求
    use_frameworks!
    use_modular_headers!
    
    flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    
    # 可手动指定Firebase版本避免冲突
    pod 'Firebase/Core', '~> 10.17.0'
    
  • 进入ios目录,执行以下命令重置Pod依赖:
    rm -rf Pods Podfile.lock
    pod install --repo-update
    

4. Xcode项目配置检查

  • 打开ios/Runner.xcworkspace(不要打开.xcodeproj),选中Runner Target:
    • 进入Build Settings,搜索Framework Search Paths,确保包含$(inherited)和$(PROJECT_DIR)/Flutter/Flutter.framework。
    • 搜索Other Linker Flags,添加-ObjC配置。
    • 检查Build Phases > Link Binary With Libraries,确认Flutter.framework及Firebase相关frameworks(如FirebaseCore.framework)已添加。

5. 清理并重新构建

  • 执行flutter clean清空项目缓存。
  • 在Xcode中执行Product > Clean Build Folder(快捷键Shift+Command+K)。
  • 重新运行flutter build ios或直接在Xcode中构建项目。

6. 检查AppDelegate.swift代码

  • 确认第二行的导入语句为import Firebase,无拼写错误。
  • 确保Firebase初始化代码在启动逻辑中,示例:
    import UIKit
    import Flutter
    import Firebase
    
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
      override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
      ) -> Bool {
        FirebaseApp.configure()
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
      }
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 01:32:47