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

问题描述 投票:0回答:4

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

我尝试设置与我的应用程序的 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

的错误

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

ios xcode firebase flutter flutter-dependencies
4个回答
25
投票

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

所以,我注意到在为 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 is Implemented 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

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


0
投票

可以看到

cloud_firestore
模块已经成功导入到你的iOS项目下了吗


0
投票

以前的解决方案都不适合我。经过两天的搜索,我将 cocoapods 降级到我知道过去可以使用的旧版本:

-COCOAPODS: 1.11.2
+COCOAPODS: 1.10.1

使用

gem uninstall cocoapods
卸载并安装旧版本。 之后我应用了@reneconrad的答案。


0
投票

当您打开 .xcodeproj 而不是打开时,可能会出现此错误消息 .xcworkspace 文件。

.xcworkspace 不仅包含应用程序项目本身,还包含 由 cocoapods 生成的项目来管理所有依赖项。

已回答找不到模块cloud_firestore

© www.soinside.com 2019 - 2024. All rights reserved.