首页 > 解决方案 > Flutter (iOS) - 在 GeneratedPluginRegistrant.m 中找不到模块“cloud_firestore”

问题描述

我是颤振环境中的新生儿。

我试图设置与我的应用程序的 Cloud Firestore 连接。我在 VSCode 上完成了大部分编码过程,但是在实现了 firestore 之后,我尝试在 Xcode 中构建,因为我在 VSCode 上遇到了一些错误。

在 Xcode 12.5.1(我使用 Rosetta 打开)中构建我的应用程序后,我收到此错误 Error when building app - Module 'cloud_firestore' not found

我确保在 Podfile 或我的 Pubspec.yaml 文件中添加依赖项。

这是我的 podfile,这是我的 pubspec.yaml 依赖项 pubspec.yaml 依赖项

我尝试了几件事,例如:

  1. 解压 pod 并重新安装 pod(包括删除 podfile.lock 和 pods 目录并重新安装 pod)

  2. 我试过flutter clean-> flutter pub get-> flutter build ios,但仍然导致同样的错误。

  3. 我已经通过 Xcode 将我的 GoogleService-Info.plist 导入到我的 Runner 并仔细检查了名称。

让我感兴趣的是,我还添加了 Firebase_auth 包,它工作得很好。查看仅在 导入 Cloud Firestore 行中显示的错误

有谁知道如何解决这个错误?任何帮助将不胜感激。太感谢了

标签: iosxcodefirebaseflutterflutter-dependencies

解决方案


经过几天的尝试和错误,我终于找到了解决问题的方法..

因此,我注意到在为 iOS 构建时可能会导致错误的几件事。

  1. 永远不要pod install手动运行命令。

  2. 不要将该行添加pod install Firebase到您的 podfile 中。相反,只需使用覆盖所有 firebase 依赖项$FirebaseSDKVersion = '8.0.0'

  3. 不要忘记在您的 podfile 中指定您的 iOS 部署目标,并将其与 Runner.xcworkspace 文件中的部署目标匹配(在运行器和目标中)

所以,如果你已经有一个项目,这里是我推荐的步骤,因为这对我来说非常有效:

  1. 删除 Pods 目录、/ios/podfile.lock 和 ios/Flutter/Flutter.podspec

  2. pod deintegrate

  3. 删除 DerivedData 文件夹中的所有内容.. 你可以运行rm -rf ~/Library/Developer/Xcode/DerivedData/*

  4. flutter clean

  5. flutter pub get

  6. 运行flutter build ios。请注意,这也将运行该pod install命令。

  7. 关闭您的编辑器,然后在 XCode 上打开您的 Runner.xcworkspace 并运行您的 XCode。清理你的构建文件夹。如果有更新项目设置的选项,请接受。

您可能会收到一些关于已弃用功能的警告,但在我的情况下,我的应用程序运行得很好。

我不知道它为什么发生的细节,但据我所知,Cocoapods 有不同版本的一些用于 ios 的 firebase 包。我希望有人能解释一下。

--

注意事项:

  • 如果在 XCode 上构建您的应用程序,然后flutter run在终端或 VSCode 上使用,您会收到一些警告,例如Class AMSupportURLConnectionDelegate isimplemented in both . 因此,根据我的个人经验,我总是从 XCode 运行我的应用程序。

  • 如果您使用 Google 登录,请按照此处的步骤操作,您无需在 podfile 中添加任何内容。

作为参考,这是我的 podfile 内容。

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

ENV['COCOAPODS_DISABLE_STATS'] = 'true'

$FirebaseSDKVersion = '8.0.0'

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)
    target.build_configurations.each do |config|
     config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
     config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
  end
end

我希望这个对你有用!祝你好运!


推荐阅读