簡體   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