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

简介: 解决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

如果不想用命令也可以直接进入这个目录,双击安装,都会弹出安装界面。

安装后,重新使用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.

相关文章
|
Swift iOS开发 Ruby
iOS CocoaPods 使用以及常见问题(上)
iOS CocoaPods 使用以及常见问题
578 0
|
CDN
Cocoapods报错 [!] CDN: trunk URL couldn't be downloaded: 解决方法
Cocoapods报错 [!] CDN: trunk URL couldn't be downloaded: 解决方法
1814 0
|
6月前
|
Dart 开发工具 Android开发
在macOS系统上配置Flutter环境的步骤
在macOS系统上配置Flutter环境的步骤
686 62
|
Oracle Java 关系型数据库
Mac电脑上安装和配置Flutter开发环境
Mac电脑上安装和配置Flutter开发环境
400 60
|
Unix iOS开发 Ruby
解决CocoaPods installed but it is not working
解决CocoaPods installed but it is not working
609 5
|
iOS开发
IOS编译出现Command PhaseScriptExecution failed with a nonzero exit code
IOS编译出现Command PhaseScriptExecution failed with a nonzero exit code
1702 2
|
iOS开发 MacOS
CocoaPods安装失败解决方法
CocoaPods安装失败解决方法
241 2
|
Dart IDE 开发工具
Flutter Version Manager (FVM): Flutter的版本管理终极指南
Flutter Version Manager (FVM): Flutter的版本管理终极指南
4866 1
|
存储 iOS开发 Perl
ios-解决报错-CocoaPods could not find compatible versions for pod “xxx“
ios-解决报错-CocoaPods could not find compatible versions for pod “xxx“
803 2
|
XML 安全 Android开发
Flutter配置Android和IOS允许http访问
Flutter配置Android和IOS允许http访问
456 3