好久没有写ios代码了,今天用xcode新建一个swift工程后,切换到工程目录,执行pod init后出错了,错误如下:
xxxmac:mySwift xxxxxxx$ pod init
――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
### Command
/usr/local/bin/pod init
### Report
* What did you do?
* What did you expect to happen?
* What happened instead?
### Stack
CocoaPods : 1.3.1
Ruby : ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]
RubyGems : 2.5.2.3
Host : Mac OS X 10.13.6 (17G65)
Xcode : 10.1 (10B61)
Git : git version 2.17.2 (Apple Git-113)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ eb17465762633ceff12d75614d2b9f8bc7e07105
### Plugins
cocoapods-deintegrate : 1.0.1
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.3/lib/xcodeproj/project.rb:217:in `initialize_from_file'
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.3/lib/xcodeproj/project.rb:102:in `open'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/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.3.1/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/bin/pod:55:in `'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `'
【RuntimeError - [Xcodeproj] Unknown object version.】原因是Xcode和cocoapods版本不匹配,更新cocoapods即可解决。
执行【gem install cocoapods --pre】命令
xxxmac:mySwift xxxxxxx$ gem install cocoapods --pre
ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:
Unable to download data from https://gems.ruby-china.org/ - bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)
【bad response Not Found 404】应该是资源路径错误【https://gems.ruby-china.org/】现在没了,换成【https://gems.ruby-china.com/】,好吧!替换source
xxxmac:mySwift xxxxxxx$ gem sources --remove https://gems.ruby-china.org/
https://gems.ruby-china.org/ removed from sources
xxxmac:mySwift xxxxxxx$ gem source -a https://gems.ruby-china.com/
https://gems.ruby-china.com/ added to sources
xxxmac:mySwift xxxxxxx$
再执行【gem install cocoapods --pre】命令
xxxmac:mySwift xxxxxxx$ gem install cocoapods --pre
Fetching: cocoapods-core-1.7.4.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
【You don’t have write permissions】:当前用户没有写权限,这好办切换到root
xxxmac:mySwift xxxxxxxxx$ sudo -i
Password:
xxxmac:~ root#
重新执行【gem install cocoapods --pre】命令
xxxmac:mySwift root# gem install cocoapods --pre
Fetching: cocoapods-core-1.7.4.gem (100%)
Successfully installed cocoapods-core-1.7.4
Fetching: cocoapods-deintegrate-1.0.4.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.4
Fetching: cocoapods-downloader-1.2.2.gem (100%)
Successfully installed cocoapods-downloader-1.2.2
Fetching: cocoapods-trunk-1.3.1.gem (100%)
Successfully installed cocoapods-trunk-1.3.1
Fetching: molinillo-0.6.6.gem (100%)
Successfully installed molinillo-0.6.6
Fetching: atomos-0.1.3.gem (100%)
Successfully installed atomos-0.1.3
Fetching: nanaimo-0.2.6.gem (100%)
Successfully installed nanaimo-0.2.6
Fetching: xcodeproj-1.11.0.gem (100%)
Successfully installed xcodeproj-1.11.0
Fetching: fourflusher-2.3.1.gem (100%)
Successfully installed fourflusher-2.3.1
Fetching: ruby-macho-1.4.0.gem (100%)
Successfully installed ruby-macho-1.4.0
Fetching: cocoapods-1.7.4.gem (100%)
Successfully installed cocoapods-1.7.4
Parsing documentation for cocoapods-core-1.7.4
Installing ri documentation for cocoapods-core-1.7.4
Parsing documentation for cocoapods-deintegrate-1.0.4
Installing ri documentation for cocoapods-deintegrate-1.0.4
Parsing documentation for cocoapods-downloader-1.2.2
Installing ri documentation for cocoapods-downloader-1.2.2
Parsing documentation for cocoapods-trunk-1.3.1
Installing ri documentation for cocoapods-trunk-1.3.1
Parsing documentation for molinillo-0.6.6
Installing ri documentation for molinillo-0.6.6
Parsing documentation for atomos-0.1.3
Installing ri documentation for atomos-0.1.3
Parsing documentation for nanaimo-0.2.6
Installing ri documentation for nanaimo-0.2.6
Parsing documentation for xcodeproj-1.11.0
Installing ri documentation for xcodeproj-1.11.0
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for ruby-macho-1.4.0
Installing ri documentation for ruby-macho-1.4.0
Parsing documentation for cocoapods-1.7.4
Installing ri documentation for cocoapods-1.7.4
Done installing documentation for cocoapods-core, cocoapods-deintegrate, cocoapods-downloader, cocoapods-trunk, molinillo, atomos, nanaimo, xcodeproj, fourflusher, ruby-macho, cocoapods after 12 seconds
11 gems installed
xxxmac:mySwift root# pod init
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:439:in `help!': [!] You cannot run CocoaPods as root. (CLAide::Help)
Usage:
$ pod COMMAND
CocoaPods, the Cocoa library package manager.
Commands:
+ cache Manipulate the CocoaPods cache
+ env Display pod environment
+ init Generate a Podfile for the current directory
+ install Install project dependencies according to versions from a
Podfile.lock
+ ipc Inter-process communication
+ lib Develop pods
+ list List pods
+ outdated Show outdated project dependencies
+ repo Manage spec-repositories
+ setup Setup the CocoaPods environment
+ spec Manage pod specs
+ update Update outdated project dependencies and create new
Podfile.lock
Options:
--silent Show nothing
--version Show the version of the tool
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.4/lib/cocoapods/command.rb:47:in `run'
from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.4/bin/pod:55:in `'
from /usr/local/bin/pod:22:in `load'
from /usr/local/bin/pod:22:in `'
更新成功,切换到工程目录,重新pod init
xxxmac:mySwift root# exit
logout
xxxmac:mySwift xxxxxxx$ pod init
xxxmac:mySwift xxxxxxx$
好了,到工程目录查看一下,Podfile文件出来了。