- 目录
- 介绍
- 日期版本
- 安装
- 使用
Podfile
- 卸载
- 安装和使用时候遇到的问题
CocoaPods
是比较出名的类库管理工具
开源:https://github.com/CocoaPods/CocoaPods
当前日期:2018.05.03
笔者系统版本:
安装
- 安装
Ruby
环境
mac
自带Ruby
,可以升级一下
$ sudo gem update --system
192:~ fengfeng$ $sudo gem update --system
Updating installed gems
Nothing to update
192:~ fengfeng$
- 请尽可能用比较新的
RubyGems
版本,建议2.6.x
以上,需翻墙
$ gem update --system
$ gem -v
192:~ fengfeng$ sudo gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.6.13.gem (100%)
Successfully installed rubygems-update-2.6.13
Parsing documentation for rubygems-update-2.6.13
Installing ri documentation for rubygems-update-2.6.13
Installing darkfish documentation for rubygems-update-2.6.13
Done installing documentation for rubygems-update after 34 seconds
Parsing documentation for rubygems-update-2.6.13
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 2.6.13
RubyGems 2.6.13 installed
Parsing documentation for rubygems-2.6.13
Installing ri documentation for rubygems-2.6.13
=== 2.6.13 / 2017-08-27
Security fixes:
* Fix a DNS request hijacking vulnerability.
Fix by Samuel Giddins.
* Fix an ANSI escape sequence vulnerability.
Fix by Evan Phoenix.
* Fix a DOS vulernerability in the `query` command.
Fix by Samuel Giddins.
* Fix a vulnerability in the gem installer that allowed
a malicious gem to overwrite arbitrary files.
Fix by Samuel Giddins.
=== ...
------------------------------------------------------------------------------
RubyGems installed the following executables:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem
Ruby Interactive (ri) documentation was installed. ri is kind of like man
pages for ruby libraries. You may access it like this:
ri Classname
ri Classname.class_method
ri Classname#instance_method
If you do not wish to install this documentation in the future, use the
--no-document flag, or set it as the default in your ~/.gemrc file. See
'gem help env' for details.
RubyGems system software updated
192:~ fengfeng$
192:~ fengfeng$ gem -v
2.6.13
192:~ fengfeng$
- 更换镜像
安装时需要访问 cocoapods.org,需要翻墙
淘宝RubyGems
镜像 https://ruby.taobao.org/ 目前已经不再维护,使用 https://gems.ruby-china.org/
执行
$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
或使用下面两命令
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://gems.ruby-china.org/
2019.02.13
因为ruby
的软件源 https://gems.ruby-china.org/ 无效了
需要更新一下ruby
的源为 https://gems.ruby-china.com/
查看$ gem sources -l
192:~ fengfeng$ gem sources -l
*** CURRENT SOURCES ***
# 确保只有 https://gems.ruby-china.org/
https://gems.ruby-china.org/
- 安装
CocoaPods
macOS 10.11
前:$ sudo gem install cocoapods
macOS 10.11
后:$ sudo gem install -n /usr/local/bin cocoapods
192:~ fengfeng$ sudo gem install cocoapods
Password:
Fetching: concurrent-ruby-1.0.5.gem (100%)
Successfully installed concurrent-ruby-1.0.5
Fetching: i18n-0.9.5.gem (100%)
Successfully installed i18n-0.9.5
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.5.gem (100%)
Successfully installed tzinfo-1.2.5
Fetching: activesupport-4.2.10.gem (100%)
Successfully installed activesupport-4.2.10
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fuzzy_match-2.0.4.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
192:~ fengfeng$ pod -version
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory
192:~ fengfeng$
出错的情况可以执行
192:~ fengfeng$ sudo gem install -n /usr/local/bin cocoapods
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-1.5.0.gem (100%)
Successfully installed cocoapods-core-1.5.0
Fetching: claide-1.0.2.gem (100%)
Successfully installed claide-1.0.2
...
Done installing documentation for fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 9 seconds
22 gems installed
192:~ fengfeng$
成功后查看版本
192:~ fengfeng$ pod --version
1.5.0
192:~ fengfeng$
-
pod setup
成功安装后,执行pod setup
所有的项目的podspec
文件都托管在https://github.com/CocoaPods/Specs
第一次执行pod setup
时,CocoaPods
会将这些podspec
索引文件更新到本地~/.cocoapods/
目录下,这个索引文件比较大
所以......超慢......
192:~ fengfeng$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git -C /Users/fengfeng/.cocoapods/repos/master fetch origin --progress
remote: Counting objects: 1296676, done.
remote: Compressing objects: 100% (319/319), done.
Receiving objects: 2% (37212/1296676), 7.40 MiB | 13.00 KiB/s
查看文件大小$ du -sh *
在未完全下载的时候执行
192:~ fengfeng$ pod repo
0 repos
192:~ fengfeng$
一晚上,断断续续的还没好,现在都青年节了🤣🤣🤣
最后我是使用git clone --depth=1 https://github.com/CocoaPods/Specs.git master
--depth
用于指定克隆深度,=1
即表示只克隆最近一次commit
参考问题2
目前最新的大概50+M
,断断续续的好久,才执行完毕
然后
192:repos fengfeng$ pod repo
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/fengfeng/.cocoapods/repos/master
1 repo
192:repos
- 下载完毕后,重新执行
pod setup
,又是漫长的等待...
但是这一步不执行即可
192:master fengfeng$ pod setup
Setting up CocoaPods master repo
Performing a deep fetch of the `master` specs repo to improve future performance
- 完毕
使用
-
cd
到项目根目录 - 创建
Podfile
文件,$ touch Podfile
,也可$ pod init
(建议) - 可以先
$ pod search ***
,找到想要的版本,记着红色标记里面的,需要写在Podfile
中
-
$ vim Podfile
,除了vim
,也可以使用其他,vim
语法暂不表述
使用 pod init 创建的,对应添加即可
touch 的全部需自己写
$ pod install
192:runtime fengfeng$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (3.2.0)
Installing SDWebImage (3.8.2)
Generating Pods project
Integrating client project
# 看这句
[!] Please close any current Xcode sessions and use `runtime.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
192:runtime fengfeng$
未执行前
执行后
$ pod install
后会有👇这句提示:
Please close any current Xcode sessions and use `runtime.xcworkspace` for this project from now on.
以后打开项目,必须使用,*****.xcworkspace
,不可使用,*****.xcodeproj
- 有时下载的一些开源项目的时候,会发现是使用
pod
来管理的,并且会有Podfile
文件存在,此时只需要cd ***
到下载好的项目根路径,然后执行pod install
即可
基本使用如此~
Podfile
- https://guides.cocoapods.org/syntax/podfile.html#podfile
- 项目根路径,初始的时候是没有
Podfile
这个文件的,需要手动创建($ touch Podfile
)或者使用$ pod init
建议使用$ pod init
,会帮你创建好基本格式
使用 pod init 创建的,对应添加即可
-
Podfile.lock
用来记录着上一次下载的版本,如下图
$ vim Podfile.lock
卸载
- 安装路径
$ which pod
192:~ fengfeng$ which pod
/usr/local/bin/pod
192:~ fengfeng$
-
$ sudo rm -rf /usr/local/bin/pod
,回车,输入密码 -
$ gem list
移除RubyGems
中的Cocoapods
程序包,RubyGems
(简称gems
)是一个用于对Ruby组件
进行打包的Ruby打包系统
。 它提供一个分发Ruby程序和库
的标准格式,还提供一个管理程序包安装的工具
查看gems
中本地程序包
192:~ fengfeng$ gem list
*** LOCAL GEMS ***
...
cocoapods (1.5.0)
cocoapods-core (1.5.0)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.2.0)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.0)
cocoapods-try (1.1.0)
...
192:~ fengfeng$
- 依次删除上面对应的包和版本
$ sudo gem uninstall cocoapods -v 1.5.0
$ sudo gem uninstall cocoapods-core -v 1.5.0
... - 可以执行,
$ pod search ...
来验证是否成功删除 - 完成
安装和使用时候遇到的问题
-
pod setup
超慢,一脸懵逼,google
到的结果
方法2不行,缺少.git
文件
实际解决方法,为问题2,虽然还是很慢,但毕竟目前才50+M
有正确解决的办法,还请指点~
- 方法1:如果同事
mac
上已经装好了,从同事电脑上copy
一份到~/.cocoapods/repos/
即可 - 方法2:从https://github.com/CocoaPods/Specs (
github
所有的第三方开源库的podspec
文件都托管在这里,这也是你pod setup所要下载的),dodwnload
或者什么方式下载到本地,然后解压,将解压后的文件移动到~/.cocoapods/repos
(这个路径是在执行pod setup
生成的,如果没有此路径,先pod setup
下,然后取消control l
即可),然后重命名为master
即可
192:runtime fengfeng$ pod setup
Setting up CocoaPods master repo
fatal: Not a git repository (or any of the parent directories): .git
[!] The `master` repo is not a git repo.
192:runtime fengfeng$
- 报错:
RPC failed; curl 18 transfer closed with outstanding read data remaining fatal: The remote end hung up unexpectedly
由于pod setup
超慢,所以想直接下载最近的一次提交,结果报错
git clone --depth=1 https://github.com/CocoaPods/Specs.git master
--depth
用于指定克隆深度,=1
即表示只克隆最近一次commit
192:repos fengfeng$ git clone --depth=1 https://github.com/CocoaPods/Specs.git master
Cloning into 'master'...
remote: Counting objects: 518394, done.
remote: Compressing objects: 100% (330152/330152), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
192:repos fengfeng$
因为,curl的postBuffer默认值太小的原因,重新在终端配置下即可
git config --global http.postBuffer 1048576000
(1GB
)(也可以把--global
去掉)
查看git config --list
但是,使用这种方法,如果在更新三方的时候使用$ pod update
会卡在Updating local specs repositories
,需要使$ pod install
192:runtime fengfeng$ pod update
Update all pods
Updating local specs repositories
Performing a deep fetch of the `master` specs repo to improve future performance
- 执行
$ pod install
会停在Analyzing dependencies
执行$ pod update
会停在Updating local specs repositories
这是因为这两个命令会升级CocoaPods
的spec
仓库
可使用👇命令:
$ pod install --verbose --no-repo-update
$ pod update --verbose --no-repo-update
不定期更新 不合适的地方 还请指点~ 感激不尽
网友评论