【问题标题】:Flutter on IOS: fatal error: module 'cloud_firestore' not foundFlutter on IOS:致命错误:找不到模块“cloud_firestore”
【发布时间】:2021-01-29 09:21:01
【问题描述】:

在 github 和 stack 上长时间搜索类似错误后,建议的解决方案都没有帮助我解决此错误。

我尝试了很多东西(有点乱):

  • 移除 IOS 派生数据
  • 更改 Firestore 软件包版本
  • 扑干净
  • rm -Rf ios/Pods
  • rm -Rf ios/.symlinks
  • rm -Rf ios/Flutter/Flutter.framework
  • rm -Rf ios/Flutter/Flutter.podspec
  • rm -rf ios/Podfile ios/Podfile.lock ios/Pods ios/Runner.xcworkspace
  • pod 初始化、安装和更新
  • 从 podfile 中取消注释平台 :ios, '9.0'(可能与此问题无关)

这是错误:

    ** BUILD FAILED **


Xcode's output:
↳
    /Users/flo/Mobile/we_ll_see/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module
    'cloud_firestore' not found
    @import cloud_firestore;
     ~~~~~~~^~~~~~~~~~~~~~~
    1 error generated.
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description

需要帮助的人

【问题讨论】:

  • 我今天遇到了类似的问题,在xcode中他说缺少一个模块,但是当我在android studio中构建项目以在ios模拟器上运行时,它给出了不同的错误, info.plist 中有错误。尝试通过android studio编译,或许对你有帮助。
  • 我得到了和 Android Studio 完全相同的错误
  • 你能在你的flutter项目的ios/文件夹中添加你的Podfile的sn-p吗?你也可以尝试从xcode 构建这个应用程序,这可能会给你一些更好的日志。
  • 您使用的是哪个版本的 firebase_core 和 cloud_firestore?

标签: ios firebase flutter google-cloud-firestore


【解决方案1】:

嗯,就我而言,问题在于部署目标。 看来默认部署目标是9.0,而Firestore需要更高的部署目标。

我更新了我的 Podfile 平台 ios,'10.0'

同样在Xcode中,从运行器项目的构建设置中,我将部署目标更改为ios 10

这对我有用。

【讨论】:

    【解决方案2】:

    ,我之前的回答不清楚。这只是我在尝试设置 Cloud Firestore 时遇到的众多错误之一,因此我没有完成整个过程。

    为了让 firebase 正常工作,您最终必须遵循此页面中的所有步骤: https://firebase.flutter.dev/docs/firestore/overview/

    如果您在生成 firebase_options.dart 文件时遇到问题,则需要按照此页面上的步骤操作: https://firebase.google.com/docs/cli#mac-linux-auto-script

    最后一步是可选的,但它减少了构建时间,我真的不知道如何或为什么,但它使其他一些错误也消失了......

    第 4 步。 改进 iOS 和 macOS 构建时间,来自此页面 https://firebase.flutter.dev/docs/firestore/overview/

    当然,别忘了在pubspec.yaml中添加依赖

    参考:https://pub.dev/packages/firebase_core/install

    这里也有关于使用Firebase.initializeApp()的精彩评论

    参考:https://stackoverflow.com/a/63492262/17626190

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案3】:

    这是一个非常糟糕且不幸的错误。在尝试解决这个问题几个小时后,我终于找到了解决方案。问题是,您的 Podfile 没有使用 pubspec.yaml 文件进行更新。我认为,您的 Podfile 几乎是空的:

    target 'Runner' do
     use_frameworks!
    
    end
    

    但那是个大问题。如果您尝试:$ rm Podfile 然后 $ pod init 将创建此 Podfile。

    这是我的解决方案:

    ...但在此之前,您必须检查一些内容,否则我的解决方案可能无法正常工作: 运行:

    $ pod install
    

    如果这个命令的结果是:

    There are 0 dependencies from the Podfile and 0 total pods installed.
    

    您可以肯定,此解决方案有效。否则它也会起作用,但也许你应该在 cmets 中写下你的命令行结果!!

    现在回到解决方案...

    1. 步骤:使用以下代码更新您的 Podfile(请删除文件的旧内容):

       ENV['COCOAPODS_DISABLE_STATS'] = 'true'
      
       project 'Runner', {
      
         'Debug' => :debug,
         'Profile' => :release,
         'Release' => :release,
       }
      
       def flutter_root
         generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
         unless File.exist?(generated_xcode_build_settings_path)
           raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
         end
      
         File.foreach(generated_xcode_build_settings_path) do |line|
           matches = line.match(/FLUTTER_ROOT\=(.*)/)
           return matches[1].strip if matches
         end
         raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
       end
      
       require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
      
       flutter_ios_podfile_setup
      
       target 'Runner' do
         use_frameworks!
         use_modular_headers!
      
      
      
         flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
       end
      
       post_install do |installer|
         installer.pods_project.targets.each do |target|
           flutter_additional_ios_build_settings(target)
         end
       end
      

    现在 Podfile 正在更新您在 podspec.yaml 文件中记下的 pod。

    现在您必须通过调用将 podspec.yaml 文件与 xcode pod 同步:

    $ pod install
    

    然后您将看到所有 pod 正在下载。在此之后,您可以通过调用 flutter run 或仅在您的编辑器中运行您的 Flutter 项目。

    注意:Podfile.lock 文件列出了 pod 和每个 pod 的版本。 'real' Podfile 仅用于 podspec.yaml 文件和真实 pod 之间的连接。如果您查看您的 Podfile.lock 文件,您会看到,没有任何 pod 被记录下来,这就是问题所在。如果没有要安装的 pod,则不会找到每个模块(例如“cloud-firestore”)...

    我希望这个答案对你有帮助,你可以在 cmets 中问我是否有问题,但我知道,这不会发生 :)

    为 macOS 编辑:

    platform :osx, '10.11'
    ENV['COCOAPODS_DISABLE_STATS'] = 'true'
    project 'Runner', {
     'Debug' => :debug,
     'Profile' => :release,
     'Release' => :release,
    }
    def flutter_root
    generated_xcode_build_settings_path = 
    File.expand_path(File.join('..', 'Flutter', 'ephemeral', 
    'Flutter- 
    Generated.xcconfig'), __FILE__)
    unless File.exist?(generated_xcode_build_settings_path)
      raise "#{generated_xcode_build_settings_path} must exist. If 
    you're running pod install manually, make sure \"flutter pub 
    get\" 
    is 
    executed first"
      end
    
      File.foreach(generated_xcode_build_settings_path) do |line|
         matches = line.match(/FLUTTER_ROOT\=(.*)/)
         return matches[1].strip if matches
       end
       raise "FLUTTER_ROOT not found in #. 
    {generated_xcode_build_settings_path}. Try deleting Flutter- 
    Generated.xcconfig, then run \"flutter pub get\""
    end
    
    require File.expand_path(File.join('packages', 'flutter_tools', 
    'bin', 'podhelper'), flutter_root)
    
    flutter_macos_podfile_setup
    
    target 'Runner' do
      use_frameworks!
      use_modular_headers!
    
      flutter_install_all_macos_pods 
    File.dirname(File.realpath(__FILE__))
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_macos_build_settings(target)
      end
    end
    

    【讨论】:

    • 是的,我遇到了这个问题,因为我因为这个错误而手动生成了 podfile:stackoverflow.com/questions/64397478/…。所以我解决了这个问题,xcode 能够找到模块。
    • 在 ios 文件夹中运行“pod install”后收到此消息。豆荚安装完成! Podfile 中有 1 个依赖项,总共安装了 10 个 pod。
    • 完美,为我工作。 ios 14.5 iphone 12 专业版,
    【解决方案4】:

    我也遇到了同样的问题,我尝试了上述所有解决方案,但都没有奏效。然后我尝试了以下步骤,它可以工作。

    flutter channel dev
    flutter upgrade
    flutter run
    

    【讨论】:

      【解决方案5】:

      完全移除 cocoapods

      sudo gem install cocoapods-deintegrate cocoapods-clean
      
      pod deintegrate
      
      pod clean
      
      rm Podfile
      

      删除 Podfile/Podfile.lock

      然后直接运行

      flutter run
      

      【讨论】:

        【解决方案6】:

        确保将从 firebase 下载的 google services info plist 文件放入与 info-plist 相同的文件夹中

        【讨论】:

          【解决方案7】:

          对我来说,我只是将部署目标更新为与 Pod 文件中定义的相同。

          请注意,您需要打开 Runner.xcworkspace 而不是 Runner.xcodeproj。

          【讨论】:

          • 这对我也有用。我在 Podfile 中碰到了平台:ios,'11.0',但忘记在 XCode 中更新它。
          • 谢谢,它对我有用
          【解决方案8】:

          分享此内容以防将来对其他人有所帮助。我和原始海报有同样的问题。我尝试了上面建议的所有解决方案,但没有一个对我有用。在撰写此消息时,至少有 5 个不同的人在 Github 上的 flutterfire 存储库中报告了相同的问题,但也没有人在那里发布明确的解决方案。

          对我有用的是删除我的 Flutter 项目中的整个 ios 目录,然后重建它:

          flutter create -i swift .
          

          这非常耗时,但它解决了问题。 'cloud_firestore' not found 错误不再发生在我身上。除了重建 ios 文件夹外,我不得不重新添加 GoogleService-Info.plist 到 Runner,重新添加图标,在 Xcode 中重新添加签名和功能,并在 Xcode 中重新添加目标属性,例如隐私使用说明,等等

          我建议先尝试上面提到的所有其他选项,但如果像我一样他们不能为您解决问题,那么删除并重建整个 ios 文件夹可能是一个有效的下一步。

          【讨论】:

            【解决方案9】:

            我试过了

            rm Podfile  
            pod init
            pod install
            

            但它总是显示已安装 0 个依赖项

            然后我删除了

            podfile.lock
            

            尝试过

            pod install again
            

            它安装了所有项目依赖项,包括 cloud_firestore。 和flutter run and flutter build ios 工作。

            【讨论】:

              【解决方案10】:

              如果您使用的是 Android Studio,如果您手动创建 Podfile,则可能会出现错误。 Flutter 仅使用 pubspec.yaml 文件运行。您不必自己设置 Podfile。如果您遵循 firestore 主页上的安装指南,只需在使用 Xcode 添加 GoogleService-Info.plist 文件后跳过所有内容。

              【讨论】:

                猜你喜欢
                • 2021-01-08
                • 2021-06-03
                • 2021-09-26
                • 2021-07-11
                • 1970-01-01
                • 2020-05-11
                • 2020-06-22
                • 2021-09-04
                • 1970-01-01
                相关资源
                最近更新 更多