繁体   English   中英

Flutter on IOS:致命错误:找不到模块“cloud_firestore”

[英]Flutter on IOS: fatal error: module 'cloud_firestore' not found

在 github 上长时间搜索并堆栈类似错误后,所提出的解决方案均未帮助我解决此错误。

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

  • 删除 IOS 派生数据
  • 更改 firestore package 版本
  • flutter 清洁
  • rm -Rf ios/Pod
  • 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 初始化,安装和更新
  • 取消注释平台:ios,来自 podfile 的“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

需要一些帮助的人

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

target 'Runner' do
 use_frameworks!

end

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

这是我的解决方案:

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

$ 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 文件中记下的 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”)...

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

为 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

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

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

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

我试过了

rm Podfile  
pod init
pod install

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

然后我删除了

podfile.lock

并尝试过

pod install again

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

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

完全去除 cocoapods

sudo gem install cocoapods-deintegrate cocoapods-clean

pod deintegrate

pod clean

rm Podfile

删除 Podfile/Podfile.lock

然后简单地运行

flutter run

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

flutter channel dev
flutter upgrade
flutter run

好吧,就我而言,问题是部署目标。 似乎默认部署目标是9.0 ,而 Firestore 需要更高的部署目标。

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

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

这对我有用。

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

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

flutter create -i swift .

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

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

,我之前的回答不清楚。 这只是我在尝试设置 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

我已经花了 2 天的时间,但我仍然不确定它是否是正确的答案,但除此之外没有任何帮助:

转到 ios 文件夹:ios -> Runner.xcodeproj -> xcshareddata -> xcschemes -> Runner.xcscheme

你必须改变:

buildImplicitDependencies = "NO" 到
buildImplicitDependencies = "是"

希望能帮助到你。 屏幕

没有一个答案对我有用,所以我添加了一个。

  1. 将 Podfile 的内容替换为以下内容。
platform :ios, '12.0'

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

def flutter_install_ios_plugin_pods(ios_application_path = nil)
  ios_application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
  raise 'Could not find iOS application path' unless ios_application_path

  symlink_dir = File.expand_path('.symlinks', ios_application_path)
  system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils.

  symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
  system('mkdir', '-p', symlink_plugins_dir)

  plugins_file = File.join(ios_application_path, '..', '.flutter-plugins-dependencies')
  plugin_pods = flutter_parse_plugins_file(plugins_file)
  plugin_pods.each do |plugin_hash|
    plugin_name = plugin_hash['name']
    plugin_path = plugin_hash['path']
    if (plugin_name && plugin_path)
      symlink = File.join(symlink_plugins_dir, plugin_name)
      File.symlink(plugin_path, symlink)

      if plugin_name == 'flutter_ffmpeg'
          pod 'flutter_ffmpeg/full-lts', :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
      else
          pod plugin_name, :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
      end
    end
  end
end

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
  1. 运行 pub 获取
  2. 运行 pod 安装

就我而言,我有一台带有 Apple 芯片的 Mac,所以我必须使用 arch -x86_64 运行 pod install

所以...首先配置您的平台,然后按照说明进行操作

扑火配置 --project=...

然后,添加 Firebase 核心库

flutter pub 添加 firebase_core

此时,如果你运行“flutter run”就会失败

所以,你必须运行

arch -x86_64 pod install --repo-update

接着

flutter运行

  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 分钟内解决此问题。

只需在 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 云存储来更改此设置。

只是繁荣。 你解决问题!!!

一段时间后,我找到了解决方案,它非常简单,对于任何试图将 flutter 应用程序存档并上传到应用程序商店并遇到未检测到 Firebase 模块问题的人,请按照以下步骤操作:

注意:如果您已经尝试过并且已经创建了 podFiles 或 plist 文件,例如 google-services.plist,请将它们全部删除并重新开始...

1- 确保在使用 mac 设备时安装 flutter SDK 和所有必要的工具(VSCode、git、Cocoapods),以防您仅将其用于部署。

2- 为 flutter 开发设置 mac 设备后,在 VSCode 上打开文件并保持打开状态。

3- 打开 XCode 和 select 打开项目或文件和 select ios 文件夹,或者您可以打开 XCode 然后返回 VSCode 并右键单击(Control + 单击)8824692977471808 文件夹“X84 和 818”。

4- go 到您的 Firebase 控制台并打开您的项目,如果您已经使用 IOS 设置了您的项目,请单击 IOS 项目并向下滚动以找到“下载 google-services.plist”,否则请为 IOS 设置您的项目只安装 google-services.plist 文件并跳过其他步骤。

5- go 到你的下载或你下载 plist 文件的地方,然后将它拖到你的 XCode 在你的“信息”文件所在的底部跑步者文件夹下。

6- go 现在到 VSCode,打开终端并键入 cd ios。

7- 这一步很神奇,在您的终端上输入 flutter pub get,您将看到在您的 ios 文件夹中生成一个自动 podFile。

8- 现在键入 pod install,恭喜 Firebase 的所有 pod 和依赖项都已正确安装。

9- 关闭 XCode 并重新打开它,选择 ios 文件夹,您会注意到文件结构发生了变化。

10- 从上面的产品点击选择目的地到“任何 ios 设备”然后存档。

祝你有美好的一天 !

你的问题可能不是什么大事。 您可能在错误的文件夹中打开了错误的文件。

因此,请检查您在 Xcode 中打开的文件夹是 Runner.xcworkspace。

您需要从 Runner.xcworkspace 文件夹而不是 Runner.xcodeproj。

对于我的情况,我只是将 pod 文件平台 ton 12.0 和 Xcode 平台更改为 12.0。 这是在将以下代码添加到 pod 文件之后

post_install 执行 |installer| installer.pods_project.targets.each 做|目标| flutter_additional_ios_build_settings(target) target.build_configurations.each 做 |config| config.build_settings['ENABLE_BITCODE'] = 'NO' config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end end end

对于仍然面临此错误的任何人,以下内容对我有用:

我面临着完全相同的错误。 我的 pod 文件看起来与问题中提出的完全一样

target 'Runner' do
  use_frameworks!

 end

我通过执行以下操作解决了:

  1. 删除ios文件夹

  2. 在主目录中,运行以下命令

    扑创建。

这将生成一个新的 ios 文件夹。

  1. 跑干净
  2. 运行 flutter pub get
  3. cd ios/ 并运行 pod install

现在应该在您的 ios 项目中正确安装所有 pod。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM