CocoaPods折腾纪实-2020-12-29

2020-12-29  本文已影响0人  勇往直前888

最近刚升级了macOS Big Sur,第二天接手了一个完成度90%的iOS项目。代码下载之后,关于CocoaPod部分完全不对。经过一番折腾,卸载了本mac上的CocoaPod,可是再装的时候就遇到了问题。只能继续折腾。

Ruby环境

CocoaPods是一个用Ruby写的、负责管理iOS项目中第三方开源库的工具。Mac电脑自带Ruby环境,可以打开终端先看一下版本:ruby -v

hello:~ zxs$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]

看版本是2.6.3,是2019年4月16日的版本,现在是2020年12月,1年多前的版本,不算高也不算低,可以先用着试试。

检查Ruby镜像源

一般要求是ruby-china比较好,这是Ruby在国内的镜像,速度相对国外的要快一些。

hello:~ zxs$ gem sources -l
Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
*** CURRENT SOURCES ***

https://gems.ruby-china.com

镜像源没问题,这个以前就更换过。可是这次多出了这些是什么鬼?Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2

安装CocoaPod不成功

hello:~ zxs$ sudo gem install -n /usr/local/bin cocoapods
Password:
Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2

又出现这个鬼:Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2

长时间卡在这里了,怎么办?

  • 直接Control + C强行退出是可以的,可是CocoaPod没装上啊
  • 后来解决了Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2,采用sudo gem install -n /usr/local/bin cocoapods仍然是长时间没有反应,需要Control + C 强行退出

解决Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2

提示里面已经有,就是gem pristine ffi --version 1.12.2,只是由于权限问题,前面要加sudo

hello:~ zxs$ sudo gem pristine ffi --version 1.12.2
Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
Restoring gems to pristine condition...
Building native extensions. This could take a while...
Restored ffi-1.12.2

gem pristine --all实际试过,这个直接用是没有效果的;

hello:~ zxs$ sudo gem update --system
Updating rubygems-update
Fetching rubygems-update-3.2.3.gem
Successfully installed rubygems-update-3.2.3
Parsing documentation for rubygems-update-3.2.3
Installing ri documentation for rubygems-update-3.2.3
Installing darkfish documentation for rubygems-update-3.2.3
Done installing documentation for rubygems-update after 87 seconds
Parsing documentation for rubygems-update-3.2.3
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.2.3

检查一下版本号:

hello:~ zxs$ gem -v
3.2.3

权限问题

CocoaPod的官网,推荐的命令很简单:

image.png

照这个命令做,会遇到权限问题:

hello:~ zxs$ sudo gem install cocoapods
Password:
Fetching cocoapods-1.10.0.gem
Fetching nanaimo-0.3.0.gem
Fetching xcodeproj-1.19.0.gem
Fetching cocoapods-downloader-1.4.0.gem
Fetching public_suffix-4.0.6.gem
Fetching addressable-2.7.0.gem
Fetching activesupport-5.2.4.4.gem
Fetching cocoapods-core-1.10.0.gem
Successfully installed nanaimo-0.3.0
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory. 这句话直接说明了这样做缺少访问权限。那怎么办?

再次尝试

直接ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory. 百度,找到了一篇文章,解释得非常清楚:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /

hello:~ zxs$ sudo gem install -n /usr/local/bin cocoapods
Password:
Successfully installed xcodeproj-1.19.0
Successfully installed cocoapods-downloader-1.4.0
Successfully installed public_suffix-4.0.6
Successfully installed addressable-2.7.0
Successfully installed activesupport-5.2.4.4
Successfully installed cocoapods-core-1.10.0
Successfully installed cocoapods-1.10.0
Parsing documentation for xcodeproj-1.19.0
Installing ri documentation for xcodeproj-1.19.0
Parsing documentation for cocoapods-downloader-1.4.0
Installing ri documentation for cocoapods-downloader-1.4.0
Parsing documentation for public_suffix-4.0.6
Installing ri documentation for public_suffix-4.0.6
Parsing documentation for addressable-2.7.0
Installing ri documentation for addressable-2.7.0
Parsing documentation for activesupport-5.2.4.4
Installing ri documentation for activesupport-5.2.4.4
Parsing documentation for cocoapods-core-1.10.0
Installing ri documentation for cocoapods-core-1.10.0
Parsing documentation for cocoapods-1.10.0
Installing ri documentation for cocoapods-1.10.0
Done installing documentation for xcodeproj, cocoapods-downloader, public_suffix, addressable, activesupport, cocoapods-core, cocoapods after 7 seconds
7 gems installed
hello:~ zxs$ pod --version
1.10.0
hello:~ zxs$ pod setup
Setup completed
hello:~ zxs$ pod repo list

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/zxs/.cocoapods/repos/master

trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/zxs/.cocoapods/repos/trunk

查找著名的AFNetworking

image.png

小结

参考文章

CocoaPods安装方法-2020.12.18

上一篇下一篇

猜你喜欢

热点阅读