异常:CocoaPods 未安装或未处于有效状态

Exception: CocoaPods not installed or not in valid state

我无法解决在调试模式下从 Visual Studio 代码启动 Flutter 应用程序时出现的以下错误。

错误:

Launching lib/app/main_dev.dart on Austris iPhone in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: P4CFB6V724
Warning: CocoaPods not installed. Skipping pod install.
  CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
  Without CocoaPods, plugins will not work on iOS or macOS.
  For more info, see https://flutter.dev/platform-plugins
To install:
  sudo gem install cocoapods

Exited (sigterm)
Exception: CocoaPods not installed or not in valid state.

Cocoapods 在那里,我现在可能已经重新安装了数十次。两者 - gem & brew。似乎没有任何效果。我试过 flutter clean,重新安装 flutter,降级 flutter 版本(低至 1.17.5)。 该错误似乎仅在我通过 Xcode.

归档 iOS 应用程序后发生

Flutter 医生也没什么好抱怨的。 奇怪的是我可以通过命令行启动应用程序(使用 flutter run)。

这是flutter doctor -v输出


[✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale en-LV)
    • Flutter version 1.20.4 at /Users/austris/Documents/DEV/flutter
    • Framework revision fba99f6cf9 (34 hours ago), 2020-09-14 15:32:52 -0700
    • Engine revision d1bc06f032
    • Dart version 2.9.2

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/austris/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = /Users/austris/Library/Android
    • ANDROID_SDK_ROOT = /Users/austris/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.7, Build version 11E801a
    • CocoaPods version 1.9.3

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 43.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.49.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.14.1

[✓] Connected device (1 available)
    • Austris iPhone (mobile) • ios • iOS 13.7

考虑重新安装 vscode。它会自动解决你的问题。编码愉快!

我使用的是 Macbook Air M1。

对我来说,它是 vs code 的 brew 版本。使用微软提供的 apple silicon 版本有效。

https://code.visualstudio.com/download

我遇到了同样的问题并通过以下步骤解决了它: (先决条件:首先安装自制软件。要检查是否已安装,请在终端中输入 $ brew -v )

  1. $ sudo gem uninstall cocoapods (如果没有安装cocoapods请跳过此部分。命令 $pod --version 会告诉你是否安装)
  2. $ brew 安装 cocoapods
  3. 如果出现错误“brew link 步骤未成功完成 构建的公式,.......,命令 $ brew link --overwrite cocoapods
  4. $ brew 重新安装 cocoapods
  5. $ 扑 运行

在这最后一步之后,如果你有 firebase 依赖并且第一次 运行ning flutter 运行,你可能会收到一个错误,要求你为平台 'iOS' 分配版本。要解决此问题,只需打开 iOS 文件夹中的 Podfile,然后取消注释 platform :ios 行并将版本更改为 10.0,例如 - platform :ios, '10.0'

我的操作系统是 macOS Big Sur。