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,就正常了。