Flutter (iOS) - 在 GeneratedPluginRegistrant.m 中找不到模块“cloud_firestore”

时间:2021-07-19 00:38:17

标签: ios xcode firebase flutter flutter-dependencies

我是flutter环境中的新生儿。

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

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

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

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

我尝试了几种方法,例如:

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

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

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

让我着迷的是,我还添加了 Firebase_auth 包,它工作得很好。查看仅在 import Cloud Firestore line

处显示的错误

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

2 个答案:

答案 0 :(得分:1)

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

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

  1. 从不手动运行命令 pod install

  2. 不要pod install Firebase 行添加到您的 podfile 中。相反,只需使用 $FirebaseSDKVersion = '8.0.0'

    覆盖所有 firebase 依赖项
  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 上构建您的应用程序,然后在终端或 VSCode 上使用 flutter run,您会收到一些警告,例如 Class AMSupportURLConnectionDelegate 已在两者中实现。所以,根据我的个人经验,我总是从 XCode 运行我的应用程序。

  • 如果您使用 Google 登录,请按照步骤 here 操作,您无需在 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

希望对你有用!祝你好运!

答案 1 :(得分:0)

您是否可以看到 cloud_firestore 模块已成功导入到您的 iOS 项目下?