一路磕磕绊绊解决flutter doctor 报错CocoaPods not installed

flutter doctor执行之后,出现以下错误:

错误消息:

shell 复制代码
    ✗ CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      For installation instructions, see
      https://guides.cocoapods.org/using/getting-started.html#installation

解决方案:flutter官网参考: https://docs.flutter.dev/get-started/install/macos/mobile-ios#install-cocoapods

安装命令:

shell 复制代码
# 查看安装进度,在最后加上-V
sudo gem install cocoapods -V 

等了N分钟,再次报错。


错误消息:

shell 复制代码
ERROR:  Error installing cocoapods:
	The last version of securerandom (>= 0.3) to support your Ruby & RubyGems was 0.3.2. Try installing it with `gem install securerandom -v 0.3.2` and then running the current command again
	securerandom requires Ruby version >= 3.1.0. The current ruby version is 2.6.10.210.

提示Ruby版本低了,升级Ruby版本。

网上方案很多,这里采用rvm版本管理的方式进行修复。更多工具参考

rvm安装参考:https://rvm.io/

执行命令:

shell 复制代码
\curl -sSL https://get.rvm.io | bash -s stable

又又报错了!


错误消息:curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 14 ms: Couldn't connect to server

解决方案:

  1. 打开网站,https://www.ipaddress.com/,在此网站中查询一下 raw.githubusercontent.com对应的IP 地址
  1. 配置hosts文件
shell 复制代码
185.199.108.133 raw.githubusercontent.com

再去执行:

shell 复制代码
\curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc',
but no GPG software exists to validate it, skipping.
Installing RVM to /Users/xxx/.rvm/
    Adding rvm PATH line to /Users/xxx/.profile /Users/xxx/.mkshrc /Users/xxx/.bashrc /Users/xxx/.zshrc.
    Adding rvm loading line to /Users/xxx/.profile /Users/xxx/.bash_profile /Users/xxx/.zlogin.
Installation of RVM in /Users/xxx/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/yangdong/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

提示还需执行:

shell 复制代码
source /Users/xxx/.rvm/scripts/rvm

才能生效。

查看是否安装成功:

shell 复制代码
rvm --version
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

使用rvm安装Ruby:

shell 复制代码
rvm install "ruby-3.4.3"

下载有点慢~

我丢,又特么报错了!

shell 复制代码
ruby-3.4.3 - #extracting ruby-3.4.3 to /Users/xxxx/.rvm/src/ruby-3.4.3 - please wait
ruby-3.4.3 - #configuring - please wait
ruby-3.4.3 - #post-configuration - please wait
ruby-3.4.3 - #compiling - please wait
Error running '__rvm_make -j10',
please read /Users/xxx/.rvm/log/1744902490_ruby-3.4.3/make.log

There has been an error while running make. Halting the installation.

查看报错:

shell 复制代码
cat /Users/xxx/.rvm/log/1744902490_ruby-3.4.3/make.log

具体报错信息:

shell 复制代码
./openssl_missing.h:195:11: warning: 'TS_VERIFY_CTS_set_certs' macro redefined [-Wmacro-redefined]
  195 | #  define TS_VERIFY_CTS_set_certs(ctx, crts) ((ctx)->certs=(crts))
      |           ^
/opt/homebrew/Cellar/openssl@3/3.4.1/include/openssl/ts.h:439:11: note: previous definition is here
  439 | #  define TS_VERIFY_CTS_set_certs(ctx, cert) TS_VERIFY_CTX_set_certs(ctx,cert)
      |           ^

查资料大概意思:

报错是发生在openssl@3,大概原因应该就是安装Ruby的时候需要编译用到openssl, 但是没有指定openssl路径的情况下,它就会默认到/usr/local/Cellar下的openssl使用,但是正常使用brew 更新或者安装过openssl的话路径并不在这里,应该在/usr/local/opt/openssl@3或者/opt/homebrew/Cellar/openssl@3 这里,具体位置报错信息有提示。这也就是导致编译的时候openssl的某些方法找不到等等错误。

解决方案:

shell 复制代码
rvm install 3.4.3 --with-openssl-dir=`brew --prefix openssl` | rvm install 3.4.3 --with-openssl-dir='/opt/homebrew/Cellar/openssl@3'

等半天~

shell 复制代码
Install of ruby-3.4.3 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri

终于成功了!

查看Ruby版本:

shell 复制代码
ruby --version
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [arm64-darwin24]

再次执行sudo gem install cocoapods -V

尼玛,又报错了~

具体报错信息:

shell 复制代码
 OpenSSL is not available. Install OpenSSL and rebuild Ruby or use non-HTTPS sources (Gem::Exception)

解决方案:

shell 复制代码
rvm reinstall 3.4.3 --with-openssl-dir=`brew --prefix openssl`

再去执行:sudo gem install cocoapods -V

终于可以了~~~耐心等待中!

shell 复制代码
Successfully installed cocoapods-1.16.2
34 gems installed

啥也不说了,特么终于安装上了!!!

再次执行flutter doctor

输出信息:

shell 复制代码
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.3, on macOS 15.4 24E248 darwin-arm64, locale zh-Hans-001)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.6)
[✓] VS Code (version 1.98.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

其中艰辛,只有两个字含泪~~~

相关推荐
融云6 小时前
集成指南:如何采用融云 Flutter IMKit 实现双端丝滑社交体验
flutter
EndingCoder17 小时前
跨平台移动开发框架React Native和Flutter性能对比
flutter·react native·react.js
Double Point17 小时前
`RotationTransition` 是 Flutter 中的一个动画组件,用于实现旋转动画效果
flutter
亚洲小炫风17 小时前
flutter 项目工程文件夹组织结构
flutter·flutter工程结构
Double Point17 小时前
Flutter 中 vsync
flutter
Double Point1 天前
ScaleTransition 是 Flutter 中的一个动画组件,用于实现缩放动画效果。
flutter
saxihuangxing1 天前
flutter build apk出现的一些奇怪的编译错误
flutter
会游泳的石头1 天前
在Java项目中实现本地语音识别与热点检测,并集成阿里云智能语音服务(优化版)
阿里云·语音识别·xcode
恋猫de小郭2 天前
Flutter 合并 ‘dot-shorthands‘ 语法糖,Dart 开始支持交叉编译
android·flutter·ios
林家凌宇2 天前
Flutter 3.29.3 花屏问题记录
android·flutter·skia