在IOS上使用Flutter: 致命错误: 找不到模块'cloud_firestore'

22

在 Github 和 Stack 上搜寻了许多小时类似的错误,但没有一个提供的解决方案能够帮助我解决这个错误。

我尝试了以下几件事(有些顺序可能不正确):

  • 删除 IOS 派生数据
  • 更改 firestore 包版本
  • flutter clean
  • 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 init,install 和 update
  • 从 podfile 中取消注释 platform :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编译,也许会有所帮助。 - Luiz Filipe Medeira
我也遇到了完全相同的错误,而且是在Android Studio中。 - Lab
你能否在 Flutter 项目的 ios/ 文件夹中添加你的 Podfile 的片段?此外,你能否尝试使用 Xcode 构建此应用程序,这可能会给你一些更好的日志。 - yusufpats
你使用的是哪个版本的 firebase_core 和 cloud_firestore? - victwise
19个回答

30

这是一个非常糟糕和不幸的错误。尝试解决了几个小时后,我终于找到了解决方案。问题是,您的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.

你可以放心,这个解决方案有效。否则它也会起作用,但也许你应该在评论中写下命令行的结果!

现在回到解决方案...

  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 文件中写下来的 pods。

现在,您需要通过调用以下命令将podspec.yaml文件与Xcode的pods同步:

$ pod install

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

注意:Podfile.lock文件列出了每个Pod的版本和Pods。'真正的' Podfile仅用于podspec.yaml文件与真正的Pod之间的连接。如果您查看Podfile.lock文件,您会发现没有任何Pod被写下来,这就是问题所在。如果没有任何Pod可安装,每个模块(例如'cloud-firestore')都将找不到...

我希望这个答案对您有所帮助,如果有什么地方不起作用,您可以在评论中问我,但我知道这不会发生:)

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

1
是的,我遇到了这个问题,因为我手动生成了Podfile,原因是由于这个错误:https://dev59.com/ar3pa4cB1Zd3GeqPksEs。所以我解决了这个问题,Xcode能够找到这些模块了。 - Lab
在 ios 文件夹内运行 pod install 后,我收到了以下消息。 Pod 安装完成!从 Podfile 中有 1 个依赖项,共安装了 10 个 pod。 - ASAD HAMEED
完美,对我有用。iOS 14.5 iPhone 12 Pro - Raiden Core
很抱歉,这可能是一个愚蠢的问题,但我来自Android,我不知道podspec.yaml文件。在我的Flutter应用程序根目录中有一个pubspec.yaml文件,在我的ios / flutter /目录中有一个flutter.podspec文件。我目前遇到了与OP相同的错误,所以我正在努力解决这个问题。 - Powermaster Prime
我无论如何都运行了你的代码,似乎部分安装成功,但遇到了这个警告/错误:[!] CocoaPods could not find compatible versions for pod "Flutter": In Podfile: Flutter (from `Flutter`) wakelock (from `.symlinks/plugins/wakelock/ios`) was resolved to 0.0.1, which depends on Flutter Specs satisfying the `Flutter (from `Flutter`), Flutter` dependency were found, but they required a higher minimum deployment target.有什么建议吗? - Powermaster Prime
2023年3月运行得非常顺利。 - Elmar

28

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

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


1
这对我也起作用了。 我在Podfile中调整了platform :ios,'11.0',但忘记在XCode中更新它。 - Alex Brinkman
谢谢!!!!整整一天都在处理这个。 - lecaro

7
如果你正在使用Android Studio,手动创建Podfile时可能会出现错误。 Flutter只需要使用pubspec.yaml文件运行。无需自己设置Podfile。如果您按照firestore主页上的安装指南操作,请跳过添加GoogleService-Info.plist文件后面的所有步骤。

4

我尝试了

rm Podfile  
pod init
pod install

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

然后我删除了它

podfile.lock

并尝试过

pod install again

它安装了包括cloud_firestore在内的所有项目依赖项。并且 flutter runflutter build ios 都可以正常工作。


4

嗯,在我的情况下,问题出在部署目标上。 默认的部署目标似乎是9.0,而Firestore需要更高的部署目标。

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

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

这对我有用。


1

我看了几种解决方案,现在我知道为什么会发生这种情况。

您可以在1分钟内解决此问题。

只需在Podfile中添加以下行:

target 'Runner' do
  pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '9.4.0' // you have to add this line
  ...
  ...
  ...
  ...
end

我正在使用标签版本:'9.4.0'。根据您使用的Firebase云存储,您可能需要更改此版本。

只需轻松解决问题!


1

完全通过以下方式删除CocoaPods

sudo gem install cocoapods-deintegrate cocoapods-clean

pod deintegrate

pod clean

rm Podfile

删除 Podfile/Podfile.lock
然后简单地运行。
flutter run

1

在我的情况下,我有一台搭载苹果芯片的 Mac,所以我必须使用 arch -x86_64 命令运行 pod install。

首先配置您的平台,并按照说明进行操作:

flutterfire configure --project=...

然后,添加 Firebase Core 库:

flutter pub add firebase_core

运行 "flutter run" 命令会失败:

flutter run

因此,进入 ios 文件夹:

cd ios

编辑 Podfile 文件,将 "platform :ios, '9.0'" 更改为 "platform :ios, '11.0'"(或更高版本):

然后执行以下命令:

arch -x86_64 pod install --repo-update

最后再次运行:

flutter run


1

分享这个信息以帮助未来的某个人。我遇到了与原贴作者相同的问题。我尝试了上面提出的所有解决方案,但都没有起作用。截至本消息编写时,至少有5个不同的人在Github的flutterfire仓库中报告了同样的问题,但没有人在那里发布了明确的解决方案。

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

flutter create -i swift .

这很耗费时间,但是解决了问题。对我而言,“cloud_firestore未找到”错误不再出现。除了重建ios文件夹外,我还需要将GoogleService-Info.plist重新添加到Runner中,重新添加图标,在Xcode中重新添加签名和能力,并在Xcode中重新添加目标属性,例如隐私使用说明等。我建议首先尝试上面提到的所有其他选项,但如果像我一样它们无法解决问题,删除并重建整个ios文件夹可能是一个有效的下一步。

1

请确保您将从Firebase下载的Google服务信息plist文件放置在与info-plist相同的文件夹中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接