【问题标题】:fatal error: module 'cloud_firestore' not found致命错误:找不到模块“cloud_firestore”
【发布时间】:2021-01-08 22:12:58
【问题描述】:

我每次尝试将 Cloud Firestore 添加到我的 Flutter 项目时都会收到此错误。我首先在我的主要项目中尝试了它,但它失败了。我在一个干净的新项目上尝试了它,每次都得到相同的结果。我已经阅读了至少 10 篇不同的帖子,其中有人遇到了这个错误。它都没有奏效。我尝试删除 Pods 和 Podfile/Podfile.lock 并生成新的。我尝试使用最新的依赖项“cloud_firestore: ^0.14.0”。


这是我的 pubspec.yaml:

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:

  cloud_firestore: ^0.14.0

  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter


这是我的 Podfile(它的一部分):

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Runner' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Runner

end

# add the Firebase pod for Google Analytics
pod 'Firebase/Analytics'
# add pods for any other desired Firebase products
# https://firebase.google.com/docs/ios/setup#available-pods

pod 'Firebase/Firestore'

我越来越痛苦了,因为我花了两天时间观看 YouTube 视频,查看了我可以查看的任何文章,但我不骗你,没有任何效果。我什至联系了 Firebase 支持以获得一些答案,但我还没有得到任何回复。

如果你碰巧知道我该如何解决这个问题,我将非常感激!

【问题讨论】:

    标签: ios xcode firebase flutter google-cloud-firestore


    【解决方案1】:

    你缺少 firebase_core

    dependencies:
      flutter:
        sdk: flutter
      firebase_core: ^0.5.0
      cloud_firestore: ^0.14.0+2
    

    查看此官方指南了解更多信息:Cloud Firestore

    【讨论】:

    • 不幸的是,这不是我的问题的原因。它丢失了,因为它是一个全新的项目,但我添加它只是为了再次确保。是的,同样的错误再次发生。致命错误:找不到模块“cloud_firestore”@import cloud_firestore;
    • flutter clean cd ios rm Pods pod install cd .. flutter run 这可能有效。链接:[github.com/FirebaseExtended/flutterfire/issues/…
    • 我已经阅读了该帖子并尝试了那里的所有内容。包括帮助其他一些人的 ncuillery 的建议。
    【解决方案2】:

    相信我,我搜索了超过 5 个小时,尝试了我在互联网上可以找到的所有解决方案。只有一部作品:

    1. 删除 Podfile、Podfile.lock、Pods 文件夹
    2. 扑干净
    3. cd ios
    4. pod deintegrate(这样 pod 不会重新安装旧库)
    5. cd ../
    6. 颤动运行

    大多数解决方案不包括第 4 步,因此即使您清理并重新安装 pod,它的行为仍然相同。 在开发者处,我们可以在 2 小时内学会如何反转二叉树,并在一天多的时间里为安装步骤苦苦挣扎,这是作为开发者最烦人的事情之一。

    【讨论】:

    • 这个解决方案对我有用!我尝试了很多东西,但只有这对我有用!感谢您节省我的时间...
    • 不客气!这也需要我很多时间。您使用的是 Mac M1 吗?
    • 嗨,我的同事正在使用它,在合并她的代码后,我遇到了这个问题。我正在使用 MacBook Pro。
    • 这个方法我试过了,还是一样..:(
    • 成功了!虽然我不知道为什么但不在乎,我很高兴。谢谢
    【解决方案3】:
    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
        platform :ios, '9.0'
        target 'Runner' do
          use_frameworks!
          use_modular_headers!
          pod 'Firebase/Core'
          pod 'Firebase/Firestore'
          pod 'Firebase/Analytics'
          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
    
    1. flutter clean
    2. flutter run

    【讨论】:

    • 终于可以构建我的应用了。谢谢!
    • 不清楚为什么这会有帮助,如果你只是盲目地复制它肯定会破坏其他东西。
    猜你喜欢
    • 2021-01-29
    • 2020-05-11
    • 2020-06-22
    • 2022-01-16
    • 2021-06-29
    • 2021-09-07
    • 2021-05-24
    • 2021-06-15
    • 2020-04-22
    相关资源
    最近更新 更多