关于cocoapods的安装和使用的一些问题

cocoapods 基本上是iOS项目中必备的第三方库管理工具. 三方库以及cocoapods的版本信息都存在Podfile.lock的.为了统一团队的开发环境,lock文件都会加入git或者svn管理.当lock有变化是,运行项目时,就会提示 pod install.

升级cocoapod出现问题

在尝试更新gem:sudo gem update --system
和升级cocoapods:sudo gem update cocoapods时,提示:

ERROR:  Error installing cocoapods:

ERROR: Failed to build gem native extension.

于是,用命令 rvm 命令发现问题如下:-bash: rvm: command not found

RVM: Ruby Version Manager, Ruby的版本管理器,包括Ruby的版本管理和Gem库管理(gemset)

说明,缺少ruby和gem库。

首先,确保已经有安装homebrew : http://brew.sh/

安装rvm

curl -L get.rvm.io | bash -s stable

安装后有这样的日志, xxx是电脑用户名

To start using RVM you need to run `source /Users/XXXXXX/.rvm/scripts/rvm`

执行 source /Users/XXXXXX/.rvm/scripts/rvm 使终端识别rvm。

source /Users/XXXXXX/.rvm/scripts/rvm

查询可用的ruby版本

rvm list known

最新可用的是ruby-2.7.0版本,安装

rvm install 2.7.0

可能提示下载错误:

Installing requirements for osx.
Updating system.....
Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba, openssl|
........
Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config libyaml readline libksba openssl',
showing last 15 lines of /Users/MTKJ/.rvm/log/1469285314_ruby-2.3.0/package_install_autoconf_automake_libtool_pkg-config_libyaml_readline_libksba_openssl.log

是因为缺少这些库,所以用homebrew挨个去安装这些库,然后在安装ruby2.7.0

brew install autoconf
brew install automake
brew install lib tool
brew install apple-gcc42
brew install libyaml
brew install libxslt
brew install libksba
brew install openssl

可能你的电脑缺少的库跟我的不一样,按照日志提示的去安装就好了。
最后,都安装好后,再执行rvm install 2.7.0。安装后,执行 rvm use ruby-2.7.0切换使用ruby270版本。然后sudo gem install cocoapods更新下载cocoapods。

rvm install 2.7.0

rvm use ruby-2.7.0

sudo gem install cocoapods

执行Pod install提示RPC failed

pod install 提示

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

以为是远程链接意外中断,剩余数据未完成读取。于是按照网上的说法,将curl的postBuffer值配置为500M。

git config --global http.postBuffer 524288000

修改后check

git config —list

修改成功

credential.helper=osxkeychain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=ZBC-CWS
http.postbuffer=524288000
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/ZBC-CWS/cocoapodsTest.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

但再执行pod install,还是出一样的错。怀疑还是国内网络原因。
于是百度cocoapods国内镜像源。找到了清华大学镜像(https://mirror.tuna.tsinghua.edu.cn/help/CocoaPods/)。
在这里插入图片描述
clone 镜像源

$ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

最后进入自己的工程,在自己工程的podFile第一行加上:

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

执行pod install,就正常了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值