解决CocoaPods installed but it is not working

简介: 解决CocoaPods installed but it is not working

问题场景

使用flutter doctor -v出现以后警告

[!] Xcode - develop for iOS and macOS (Xcode 12.4)
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods. For more info, see https://github.com/flutter/flutter/issues/14293.
      To re-install CocoaPods, run:
        sudo gem install cocoapods  

然后将运行项目在IOS中,出现以下报错

Launching lib/main.dart on iPhone 12 in debug mode...
Warning: CocoaPods is installed but broken. Skipping pod install.
  You appear to have CocoaPods installed but it is not working.
  This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
  This can usually be fixed by re-installing CocoaPods. For more info, see https://github.com/flutter/flutter/issues/14293.
To re-install:
  sudo gem install cocoapods

CocoaPods not installed or not in valid state.
Error launching application on iPhone 12.

解决方法

看错误提示的是Ruby的版本和CocoaPods的版本不对应产生的问题。

安装RVM

Ruby Version Manager(Ruby版本管理器)是用于类UNIX操作系统的软件平台,用于管理同一设备上Ruby的多个安装。

$ curl -L https://get.rvm.io | bash -s stable

安装完成后,根据提示使用source命令使rvm生效。

# 根据自己电脑使用的环境变量使用对应的命令,如果不知道就2条命令都使用。
$ source ~/.bash_profile
$ source ~/.bashrc

接着关闭Terminal,然后再重新打开。

安装ruby 2.6版本

使用上面安装的RVM来安装ruby 2.6

$ rvm install ruby-2.6

安装完成后,会显示安装的具体版本。笔者写这篇文章的时候2.6最新的版本是2.6.6。

接着切换ruby版本

$ rvm use ruby-2.6.6

设置当前版本为默认版本,这样一来以后新打开的控制台默认的 Ruby 就是这个版本

$ rvm --default use 2.6.6

最后重新安装CocoaPods

$ sudo gem install cocoapods

这样安装的pod会自动跟当前的Ruby版本对应上。

再次运行flutter doctor就不会有错误了。

相关文章
kali2022.1The following packages were automatically installed and are no longer required
kali2022.1The following packages were automatically installed and are no longer required
81 1
解决ERROR: Cannot uninstall ‘llvmlite‘. It is a distutils installed project and thus we cannot accurat
解决ERROR: Cannot uninstall ‘llvmlite‘. It is a distutils installed project and thus we cannot accurat
961 0
解决ERROR: Cannot uninstall ‘llvmlite‘. It is a distutils installed project and thus we cannot accurat
解决ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accuratel
解决ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accuratel
525 0
解决ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accuratel
configure: error: Library requirements (libpcre >= 7.8) not met
configure: error: Library requirements (libpcre >= 7.8) not met
134 0
|
Python
【解决方案】解决CMake must be installed to build the following extensions: pyltp
【解决方案】解决CMake must be installed to build the following extensions: pyltp
213 0
|
虚拟化 Docker Windows
成功解决VirtualBox is not installed. Please re-run the Toolbox Installer and try again.
成功解决VirtualBox is not installed. Please re-run the Toolbox Installer and try again.
成功解决VirtualBox is not installed. Please re-run the Toolbox Installer and try again.
|
API 开发工具 Android开发
Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
941 0
Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
|
Android开发 iOS开发 Perl
Flutter Warning: CocoaPods not installed. Skipping pod install.
Flutter Warning: CocoaPods not installed. Skipping pod install.
672 0
Linter pylint is not installed
问题 Linter 'pylint' is not installed. Please install it or select another linter". Error: Module 'pylint' not installed.
2977 0