CocoaPods无法找到与“Firebase / CoreOnly”兼容的版本。

186

我已将我的Flutter包更新到最新版本,现在IOS不再工作。

当我尝试更新Pods时,它显示以下错误:

    [!] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly":
    In Podfile:
    cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`) was resolved to 0.0.1, which depends on
    Firebase/Firestore (~> 6.0) was resolved to 6.0.0, which depends on
    Firebase/CoreOnly (= 6.0.0)

    cloud_functions (from `.symlinks/plugins/cloud_functions/ios`) was resolved to 0.0.1, which depends on
    Firebase/Functions (~> 5.18) was resolved to 5.18.0, which depends on
    Firebase/CoreOnly (= 5.18.0)

这是我的 pubspec.yaml 文件(与 Firebase 相关):

firebase_core: "^0.4.0"
firebase_auth: "^0.11.0"
firebase_analytics: "^3.0.0"  
cloud_firestore: "^0.11.0+1"
cloud_functions: "^0.3.0"
firebase_storage: "^3.0.0"
firebase_messaging: "^5.0.1"

我已经采取了各种措施来尝试修复:

flutter clean
flutter build ios

pod install
pod update
pod repo update
pod install --repo-update

我在 Podfile 和 Xcode 中将平台设置为 :ios,'12.1',但仍然无法正常工作。

这是我的 Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '12.1'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  pods_ary = []
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) { |line|
      next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
      plugin = line.split(pattern=separator)
      if plugin.length == 2
        podname = plugin[0].strip()
        path = plugin[1].strip()
        podpath = File.expand_path("#{path}", file_abs_path)
        pods_ary.push({:name => podname, :path => podpath});
      else
        puts "Invalid plugin specification: #{line}"
      end
  }
  return pods_ary
end

target 'Runner' do
  use_frameworks!

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')

  # Flutter Pods
  generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
  if generated_xcode_build_settings.empty?
    puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
  end
  generated_xcode_build_settings.map { |p|
    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
      symlink = File.join('.symlinks', 'flutter')
      File.symlink(File.dirname(p[:path]), symlink)
      pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
    end
  }

  # Plugin Pods
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.map { |p|
    symlink = File.join('.symlinks', 'plugins', p[:name])
    File.symlink(p[:path], symlink)
    pod p[:name], :path => File.join(symlink, 'ios')
  }
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

我不熟悉Flutter的yaml文件,但是0.11.0+1看起来很可疑,因为FirebaseFirestore需要Firebase 6.x,而FirebaseFunctions需要Firebase 5.x。 - Paul Beusterien
如果被接受的答案没有帮助,我会在另一个问题下面放置我的答案。https://dev59.com/aFQK5IYBdhLWcg3wJMgm#69047809 - Hesam
33个回答

386

如果问题没有解决,尝试调用pod repo update

在根目录中删除Podfile.lock后,运行pod install


97
对我而言,删除 Podfile.lock 文件后再运行 pod install 命令可以解决我的问题。 - emrcftci
20
针对 M1 Mac:别名 pod="arch -x86_64 pod" - Ajay Gautam
5
Flutter 3 对我来说无法使用。 - Faiizii Awan
5
rm -rf Podfile.lock && pod install --repo-update感谢 @Mohhamed Nabil - PhillipJacobs
pod repo update 对我来说有效! - undefined
显示剩余4条评论

166

在podfile中编辑最低的iOS版本,然后运行pod install。

platform :ios, '9.0' 更改为 platform :ios, '10.0',然后运行 pod install,这对我解决了问题。


2
当我在Xcode中更改“Runner”->“Runner”->“Info”->“iOS Deployment Target”版本为>= 10.0.0时,它完美地工作。 - Julian Schmuckli
这对我也奏效了。删除 Podfile.lock,然后运行 pod repo updatepod install - sunderee

111

对于M1 Mac用户

  1. 进入项目中的ios/Pods/Local Podspecs目录
  2. 检查每个json文件,找到最高所需的iOS版本。在其中一些文件中,我的版本是"ios": "10.0"
  3. 返回到ios/目录
  4. 打开Podfile文件
  5. 取消注释# platform :ios, '9.0'并将步骤2中的版本号9.0替换为相应的版本号。例如,10.0

接下来是针对M1芯片的特定部分

6. 运行 `sudo arch -x86_64 gem install ffi` 7. 运行 `arch -x86_64 pod repo update` 8. 运行 `arch -x86_64 pod install`,错误应该会消失 9. 如果使用Flutter,请使用 `cd -` 返回到根目录 - 打开iOS模拟器并运行 `flutter run` 10. 如果不起作用,可能需要在第一步之前运行 `flutter pub add firebase_core` 将firebase_core添加到你的 `pubspec.yaml` 文件中
如果还不起作用,请尝试以下附加步骤:
  • 尝试直接从Xcode运行?首先在Flutter项目中运行flutter build ios,然后在Xcode中运行

  • 仍然不起作用cd iOS运行rm -rf Pods/ Podfile.lock ; pod install

  • 仍然不起作用?在Spotlight中搜索钥匙串访问 -> 打开 -> 右键单击登录 -> 解锁(构建成功后会重新锁定)

  • 仍然不起作用?Xcode Runner Info Screenshot 确保您的Runner Info配置如下所示


37

只需执行pod update,然后执行pod install。这对我有效。


28
  1. 执行 flutter clean

  2. 进入 ios/ 文件夹,编辑 Podfile 并选择你想要启动的平台和版本。例如,对于平台ios和版本12.0

Podfile

# Uncomment this line to define a global platform for your project
platform :ios, '12.0'
  1. 执行 pod update

  2. 执行 pod install (下载依赖可能需要几分钟时间)

  3. 执行 flutter run


27
如果您正在使用M1 Mac,请通过运行以下命令删除podfile.lock。
arch -x86_64 rm -rf Podfile.lock

然后通过运行更新pods

arch -x86_64 pod install --repo-update

非常感谢,这对我有用,因为我是M1用户。 - Mohammed_7aafar
如果你需要在 Rosetta 中运行任何 pod 安装,则说明你的机器没有正确设置。 - Karatekid430
我找到的唯一可行且最简单的解决方案! - c.lamont.dev
您可以在非英特尔架构下运行rm命令。 - domfz
如果我不在 Mac M1 上运行第一个命令,会有什么影响?我在普通的 Mac Intel 上运行了它,结果出错了。我想我可能真的搞砸了什么... - Andrew Colin

16

适用于M1 Mac

最后一部分是找到答案最简单、最快捷的方法。

进入ios文件夹:

cd ios

方法1:

打开终端并运行以下命令:

sudo gem uninstall cocoapods
sudo gem install cocoapods

重新启动IDE或编辑器

方法2:

注意:仅在方法1无效时尝试

现在是时候为M1 Mac安装pod了:

 sudo arch -x86_64 gem install ffi
 arch -x86_64 pod repo update
 arch -x86_64 pod install

现在,99%的安装错误应该已经解决了。

现在只有1%的可能性仍然会出现错误:

打开你的iOS Runner XCode项目并按照图片说明操作。

将目标架构中的排除架构更改为架构

form i386 to arm64 i386 (Note: space is important)

enter image description here

现在回到根目录并运行

 flutter run

另外,重新启动你的编辑器。

高级提示:

如果你多次遇到这个错误并且每次都需要复制粘贴才能解决,那么我在这里提供一种更好的方法来完成它,使用第二种方法:

复制下面的代码:

#!/bin/bash

pwd
sudo arch -x86_64 gem install ffi
arch -x86_64 pod repo update
arch -x86_64 pod install

您需要在IOS文件夹中创建一个脚本文件,我们称其为pod_install.sh。如果您再次遇到同样的问题,您只需要运行一个命令即可。

sh pod_install.sh 

从你的 iOS 文件夹中

现在输入你 Mac 的密码

现在是喝茶 ☕ 的时间

别忘了重新启动你的编辑器。


1
arch -x86_64 pod repo update 这个命令对我很有效... 之后,我可以通过 arch -x86_64 pod install 命令在 M1 上安装 pod... - Wahab Khan Jadon
在 M2 Mac 上,执行命令 sudo arch -x86_64 gem install ffi 时出现错误 "arch: posix_spawnp: gem: Bad CPU type in executable"。 - markhorrocks

14

enter image description here

使用版本为^1.0.3的"firebase_core"依赖项时,"iOS部署目标"不能低于"10.0"。

HERO,花了两天时间才弄清楚M1的设置,尽管他们一直在使用M1,但出于某种原因它停止了。而且,除非使用这些方法,否则pod install或update再也无法正常工作。再次感谢。 - Huthaifa Muayyad

8
我在尝试将Firebase Analytics添加到我的项目中时遇到了同样的问题。我一直在终端中运行pod update,但直到我确保pubspec.yaml文件中所有flutter包都是最新版本之后,才能成功获取到FirebaseCore(6.0.0)。
1)我删除了导致错误的包。对我来说,它是Firebase Analytics,因为我刚刚将其添加到我的项目中。
2)我检查了所有firebase包,并确保我在pubspec.yaml中拥有最新版本。以下是它们:
firebase_core: ^0.4.0
firebase_database: ^3.0.0
firebase_auth: ^0.11.0
firebase_storage: ^3.0.0

3)导航到ios文件夹并运行pod update。

4)将Firebase Analytics包(或您感兴趣的任何内容)添加到pubspec.yaml中。

5)运行packages get命令。

6)在终端中运行pod install命令。


8

March 2021

cloud_firestore: ^1.0.0

cd ios
rm Podfile.lock
pod repo update

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接