解决CocoaPods安装卡住反应慢或失败


使用Flutter打包IOS,都会有三方依赖。IOS的依赖是用CocoaPods来管理的。使用Flutter doctor会提示安装CocoaPods.

根据提示安装CocoaPods,直接安装就卡在这里一直不动了。

$sudo gem install cocoapods

在网上找到个参数,可以查看安装进度,在最后加上-V。

# 注意V是大写
$sudo gem install cocoapods -V 

看到安装过程,发现是网的问题,因为gem的源地址在国外

解决gem安装慢或卡住

  • 使用梯子直接安装。
  • 将gem的源改为国内镜像。

替换源是最简单的方法

# 替换源
$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
# 查看替换后的源地址
$ gem sources -l
https://gems.ruby-china.com
# 确保只有 gems.ruby-china.com

解决Failed to build gem native extension

替换gem源之后安装到最后又碰到以下问题。

Building native extensions.  This could take a while...
current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.14.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20210203-987-tfjdrx.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
ERROR:  Error installing cocoapods:
	ERROR: Failed to build gem native extension.

    Building has failed. See above output for more information on the failure.
extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.14.2 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.14.2/gem_make.out

Google搜索发现是MacOS缺少一些头文件。因为我的是10.14。所以直接使用以下命令安装工具包。

$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

如果不想用命令也可以直接进入这个目录,双击安装,都会弹出安装界面。
macOS_SDK_headers_for_macOS_10.14
安装后,重新使用sudo gem install cocoapods就能安装成功了。

最后运行Flutter doctor,IOS显示正常。

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, 1.22.6, on Mac OS X 10.14.6 18G7016 darwin-x64,
    locale zh-Hans-CN)

[] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[] Android Studio (version 4.0)
[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.
  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值