CocoaPods升级

最新新建了一个项目,使用CocoaPods,在项目根目录执行Pod init时报错

$ pod init

出现报错信息,如下:

/usr/local/bin/pod init
   CocoaPods : 1.4.0
        Ruby : ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
    RubyGems : 2.6.14
        Host : Mac OS X 10.13.4 (17E199)
       Xcode : 9.4.1 (9F2000)
         Git : git version 2.15.2 (Apple Git-101.1)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ fc527ae9db826735554c0163d8a849dc7562ead8
### Plugins
cocoapods-deintegrate : 1.0.2
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
### Error
RuntimeError - [Xcodeproj] Unknown object version.
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.4/lib/xcodeproj/project.rb:217:in `initialize_from_file'
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.4/lib/xcodeproj/project.rb:102:in `open'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/command/init.rb:41:in `validate!'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:333:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/bin/pod:55:in `'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `
' [!] Oh no, an error occurred. Search for existing GitHub issues similar to yours: https://github.com/CocoaPods/CocoaPods/search?q=%5BXcodeproj%5D+Unknown+object+version.&type=Issues If none exists, create a ticket, with the template displayed above, on: https://github.com/CocoaPods/CocoaPods/issues/new Be sure to first read the contributing guide for details on how to properly submit a ticket: https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md Don't forget to anonymize any private data! and 41 more at: https://github.com/cocoapods/cocoapods/search?q=[Xcodeproj]%20Unknown%20object%20version.&type=Issues&utf8=✓

执行Pod init的时候一直报错,但是没找到根本解决方案,所以最后决定升级一下CocoaPods(现在的版本是1.4.0,最新的版本是1.5.3)

pod --version   //查看当前的版本号
1.4.0
gem source -l   //查看当前安装的Ruby源地址
*** CURRENT SOURCES ***

https://ruby.taobao.org/

移除淘宝的Ruby源,添加一个新的源

//移除淘宝的Ruby源
gem sources --remove https://ruby.taobao.org/
//添加一个新的源
gem sources -a https://gems.ruby-china.org/

此时查看Ruby源地址,已经换成https://gems.ruby-china.org/

gem source -l
*** CURRENT SOURCES ***

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

开始安装升级,输入密码

sudo gem install cocoapods
Password:
Fetching: cocoapods-core-1.5.3.gem (100%)
Successfully installed cocoapods-core-1.5.3
Fetching: cocoapods-downloader-1.2.1.gem (100%)
Successfully installed cocoapods-downloader-1.2.1
Fetching: molinillo-0.6.5.gem (100%)
Successfully installed molinillo-0.6.5
Fetching: atomos-0.1.2.gem (100%)
Successfully installed atomos-0.1.2
Fetching: nanaimo-0.2.6.gem (100%)
Successfully installed nanaimo-0.2.6
Fetching: xcodeproj-1.5.9.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

出现报错信息,执行

sudo gem install -n /usr/local/bin cocoapods
Successfully installed xcodeproj-1.5.9
Fetching: cocoapods-1.5.3.gem (100%)
Successfully installed cocoapods-1.5.3
Parsing documentation for xcodeproj-1.5.9
Installing ri documentation for xcodeproj-1.5.9
Parsing documentation for cocoapods-1.5.3
Installing ri documentation for cocoapods-1.5.3
Done installing documentation for xcodeproj, cocoapods after 5 seconds
2 gems installed

安装成功后,查看CocoaPods版本

pod --version
1.5.3

已经升级到最新版本,现在去项目根目录执行Pod init时正常创建Podfile文件

你可能感兴趣的:(CocoaPods升级)