iOS-Mac下安装CocoaPods

4 篇文章 0 订阅

关于CocoaPods,是OS X和iOS下的一个第三方类库管理工具,它的好处这里不多说,主要说下如何安装CocoaPods。

CocoaPods的安装需要Ruby环境,Mac系统都自带Ruby,通过下面终端命令查看Ruby版本:

ruby -v

CocoaPods支持的Ruby最低版本是2.2.2,如果自己的版本低于2.2.2就需要更新升级Ruby:

sudo gem update --system

我的没更新

更换Ruby镜像

Ruby默认的源地址是国外网络地址,通过下面终端命令查看当前镜像地址:

gem sources -l

** CURRENT SOURCES **

https://rubygems.org/

首先移除当前镜像

gem sources --remove https://rubygems.org/

然后添加国内最新Ruby镜像地址

gem sources -a https://gems.ruby-china.com/
https://gems.ruby-china.com/added to sources

这时候再查看镜像地址就是这样的了

*** CURRENT SOURCES ***

https://gems.ruby-china.com/

安装CocoaPods

Ruby环境安装好以后,接下来就是安装CocoaPods,终端输入:

sudo gem install cocoapods

报错

Building native extensions. This could take a while…

ERROR: Error installing cocoapods:

ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/ext/ffi_c

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I
/Library/Ruby/Site/2.6.0 -r ./siteconf20210113-23968-1w6mjuz.rb
extconf.rb

checking for ffi.h… *** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of
necessary

libraries and/or headers. Check the mkmf.log file for more details.
You may

need configuration options.

Provided configuration options:

–with-opt-dir

–without-opt-dir

–with-opt-include

–without-opt-include=${opt-dir}/include

–with-opt-lib

–without-opt-lib=${opt-dir}/lib

–with-make-prog

–without-make-prog

–srcdir=.

–curdir

–ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)

–with-ffi_c-dir

–without-ffi_c-dir

–with-ffi_c-include

–without-ffi_c-include=${ffi_c-dir}/include

–with-ffi_c-lib

–without-ffi_c-lib=${ffi_c-dir}/lib

–enable-system-libffi

–disable-system-libffi

–with-libffi-config

–without-libffi-config

–with-pkg-config

–without-pkg-config

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in
`try_do’: The compiler failed to generate an executable file.
(RuntimeError)

You have to install development tools first.

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in
`block in try_compile’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in
`with_werror’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in
`try_compile’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in
`block in have_header’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in
`block in checking_for’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in
`block (2 levels) in postpone’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in
`open’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in
`block in postpone’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in
`open’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in
`postpone’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in
`checking_for’

from
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in
`have_header’

from extconf.rb:10:in `system_libffi_usable?’

from extconf.rb:42:in `’

To see why this extension failed to compile, please check the mkmf.log
which can be found here:

/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2 for inspection.

Results logged to
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/gem_make.out

原因是因为

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:找不到这个

检查一下本地的目录是

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:

注意

在找ruby-2.6.0的时候,因为每个人的ruby环境不一样所以要注意自己的目录是否是对的上我的是ruby 2.6.3,所以不建议直接复制目录cd进去,一步步找自己本地的文件

我的路径是

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0

解决方案

报错里提示universal-darwin19 本地的却是universal-darwin20

所以将20复制粘贴将universal-darwin20文件改成universal-darwin19

sudo gem install cocoapods

参考文章:

https://www.jianshu.com/p/f00be46d77ef

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

特特专属

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值