彻底解决 CocoaPods not installed or not in valid state

一、问题

最近在学习Flutter ,在使用Android Studio运行一个开源的Flutter项目时,总是编译失败,并提示如下内容:

lib/main.dart:1
Automatically signing iOS for device deployment using specified development team in Xcode project: xxxxxx
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 see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

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

二、问题分析

上面的提示现在看来很有误导性。
我们先看看第一段提示

Warning: CocoaPods not installed. Skipping pod install.

这是告诉你,你的电脑没有安装CocoaPods。如何知道电脑有没有安装?可以在Terminal执行下面的指令:

gem list

在这里插入图片描述
如果执行完后没有红色框框的内容,那说明确实没有安装。那么需要执行下面的指令:

sudo gem install cocoapods

如果上面红色框框里有了Cocoapods,还报这个错误,那就上面那个提示就是坑。
再来看看最后两行提示(中间都是来描述Cocoapods的作用,简单来说我运行的开源项目里用了很多第三方依赖插件,Cocoapods的作用就是来管理这些插件,解决依赖问题)

For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

上面两段就是贴了两个网址,官方告诉你若想解决问题,需要访问https://guides.cocoapods.org/using/getting-started.html#installation,
但是当你看这个网站里的描述并操作一遍发现,还是没啥用,因为它还是让你安装Cocoapods,但是你明明已经安装了,现在问题变成了死循环。

三、问题解决

网上有很多尝试解决这个问题的描述,大部分要么是你重装Cocoapods,要么就是重新启动Android Studio。这些基本没啥用,直到在Stack Overflow 上看到一位大佬解决办法,很简单,只需要执行如下操作:
1、将Android Studio 关闭
2、执行如下指令

open /Applications/Android\ Studio.app

例如:
在这里插入图片描述
这个时候会开启Android Studio,并出现如下界面:
在这里插入图片描述
接着我们打开一个刚刚一直编译失败的开源项目,比如上面的animations 项目,
然后在运行起来:
在这里插入图片描述
大功告成!

至于为什么要通过执行

open /Applications/Android\ Studio.app

才能正常编译运行。大佬是这么解释的:
在这里插入图片描述
翻译下就是:

问题是有三种可能的资源路径,您可以将路径放在配置中。。。。

因此,当您的配置路径不在~/中时,就会发生这种情况。配置文件,无法从启动板的打开链接访问它。无论何时打开终端会话,所有3条路径都会自动同步。这就是区别。

一句话总结:这个BUG是Android Studio的配置问题,或者是自己电脑环境的配置问题。

猜你喜欢

转载自blog.csdn.net/qq_26439323/article/details/127379136
今日推荐