前言:記錄一些在CocoaPods使用過程中遇到的問題,本地環境:Xcode9.0
- 發現有的時候在執行pod init的時候不能正常地創建出來pod File文件,顯示的錯誤如下:

1 ――― MARKDOWN TEMPLATE ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― 2 3 ### Command 4 5 ``` 6 /Users/wangyongwangyongwang/.rvm/rubies/ruby-2.3.0/bin/pod init 7 ``` 8 9 ### Report 10 11 * What did you do? 12 13 * What did you expect to happen? 14 15 * What happened instead? 16 17 18 ### Stack 19 20 ``` 21 CocoaPods : 1.0.1 22 Ruby : ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] 23 RubyGems : 2.6.6 24 Host : Mac OS X 10.12.6 (16G29) 25 Xcode : 9.0 (9A235) 26 Git : git version 2.10.1 27 Ruby lib dir : /Users/wangyongwangyongwang/.rvm/rubies/ruby-2.3.0/lib 28 Repositories : master - https://github.com/CocoaPods/Specs.git @ 74d8002565cb1b582426b5affef1b97991b4c14c 29 ``` 30 31 ### Plugins 32 33 ``` 34 cocoapods-deintegrate : 1.0.1 35 cocoapods-plugins : 1.0.0 36 cocoapods-search : 1.0.0 37 cocoapods-stats : 1.0.0 38 cocoapods-trunk : 1.0.0 39 cocoapods-try : 1.1.0 40 ``` 41 42 ### Error 43 44 ``` 45 RuntimeError - [Xcodeproj] Unknown object version. 46 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0@global/gems/xcodeproj-1.3.0/lib/xcodeproj/project.rb:217:in `initialize_from_file' 47 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0@global/gems/xcodeproj-1.3.0/lib/xcodeproj/project.rb:102:in `open' 48 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0@global/gems/cocoapods-1.0.1/lib/cocoapods/command/init.rb:41:in `validate!' 49 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0@global/gems/claide-1.0.0/lib/claide/command.rb:333:in `run' 50 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0@global/gems/cocoapods-1.0.1/lib/cocoapods/command.rb:50:in `run' 51 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0@global/gems/cocoapods-1.0.1/bin/pod:55:in `<top (required)>' 52 /Users/wangyongwangyongwang/.rvm/rubies/ruby-2.3.0/bin/pod:22:in `load' 53 /Users/wangyongwangyongwang/.rvm/rubies/ruby-2.3.0/bin/pod:22:in `<main>' 54 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval' 55 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>' 56 ``` 57 58 ――― TEMPLATE END ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― 59 60 [!] Oh no, an error occurred. 61 62 Search for existing GitHub issues similar to yours: 63 https://github.com/CocoaPods/CocoaPods/search?q=%5BXcodeproj%5D+Unknown+object+version.&type=Issues 64 65 If none exists, create a ticket, with the template displayed above, on: 66 https://github.com/CocoaPods/CocoaPods/issues/new 67 68 Be sure to first read the contributing guide for details on how to properly submit a ticket: 69 https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md 70 71 Don't forget to anonymize any private data! 72 73 wangwang:WWTestCocoaPodsError wangyongwangyongwang$
解決問題:根據錯誤提示可以發現參考 使用CocoaPods出現問題的時候都可以查看CocoaPods issues 我這邊的錯誤是參考的 pod init error #7208
解決方法:關鍵的命令是這一句:Try gem install cocoapods -v 1.4.0.beta.2
or gem install cocoapods -v 1.3.1
然后就沒問題了
插曲:其實我在解決上邊問題的時候,第一次忘了輸入cocoapods了,然后報錯如下
ERROR: While executing gem ... (Gem::CommandLineError)
Please specify at least one gem name (e.g. gem build GEMNAME)
解決辦法:后來我正確輸入命令沒問題后,就解決了這個問題了
自我分析:上邊的命令是讓我們更新Cocoapods到1.3.1版本,我在更新前都是用的比較老的1.0.1 (pod --version查看安裝的Cocoapods的版本)
多想一點CocoaPods的本質到底是什么:
深入理解 CocoaPods 提到CocoaPods 是開發 OS X 和 iOS 應用程序的一個第三方庫的依賴管理工具。CocoaPods是用 Ruby 寫的,並由若干個 Ruby 包 (gems) 構成的。所以她才會用gem intall 這種方式安裝Cocoapods
CocoaPods是這么說自己的:CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 39 thousand libraries and is used in over 2.7 million apps. CocoaPods can help you scale your projects elegantly.CocoaPods is built with Ruby and is installable with the default Ruby available on OS X. We recommend you use the default ruby.
CocoaPods是對於Swift和Objective-C的Cocoa項目的依賴管理工具,她已有39000多個庫,並且應用於27萬多個app。CocoaPods可以幫助你使你的項目更小更優雅。CocoaPods的基礎是Ruby,並且OS X上默認已經安裝了Ruby,我們建議您使用默認的Ruby。
2.在使用pod update --verbose --no-repo-update的時候不能夠正常地導入所要導入的第三方庫
我要導入的庫是 pod 'CYLTabBarController', '~> 1.14.1'
提示的問題是:

1 Update all pods 2 Preparing 3 4 Analyzing dependencies 5 6 Inspecting targets to integrate 7 Using `ARCHS` setting to build architectures of target 8 `Pods-WWCopyHomeWorkBox`: (``) 9 Using `ARCHS` setting to build architectures of target 10 `Pods-WWCopyHomeWorkBoxTests`: (``) 11 Using `ARCHS` setting to build architectures of target 12 `Pods-WWCopyHomeWorkBoxUITests`: (``) 13 14 Resolving dependencies of `Podfile` 15 [!] Unable to satisfy the following requirements: 16 17 - `CYLTabBarController (~> 1.14.1)` required by `Podfile` 18 19 None of your spec sources contain a spec satisfying the dependency: `CYLTabBarController (~> 1.14.1)`. 20 21 You have either: 22 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`. 23 * mistyped the name or version. 24 * not added the source repo that hosts the Podspec to your Podfile. 25 26 Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default. 27 28 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/resolver.rb:461:in `handle_resolver_error' 29 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/resolver.rb:80:in `rescue in resolve' 30 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/resolver.rb:72:in `resolve' 31 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/installer/analyzer.rb:771:in `block in resolve_dependencies' 32 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/user_interface.rb:64:in `section' 33 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/installer/analyzer.rb:768:in `resolve_dependencies' 34 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/installer/analyzer.rb:79:in `analyze' 35 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:242:in `analyze' 36 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:154:in `block in resolve_dependencies' 37 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/user_interface.rb:64:in `section' 38 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:153:in `resolve_dependencies' 39 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/installer.rb:116:in `install!' 40 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command/update.rb:81:in `run' 41 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run' 42 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command.rb:52:in `run' 43 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/gems/cocoapods-1.3.1/bin/pod:55:in `<top (required)>' 44 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/bin/pod:22:in `load' 45 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/bin/pod:22:in `<main>' 46 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval' 47 /Users/wangyongwangyongwang/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
檢查了本地的版本:pod --version

1 wangwang:WWCopyHomeWorkBox wangyongwangyongwang$ pod --version 2 1.3.1
檢查pod 庫中是否存在我們要添加的相應的版本的pod庫:當我執行pod Search CYLTabBarController的時候顯示如下:顯示表明 pod 庫里邊有我要添加的這個版本

1 wangwang:WWCopyHomeWorkBox wangyongwangyongwang$ pod search CYLTabBarController 2 3 4 -> CYLTabBarController (1.14.2) 5 Highly customizable tabBar and tabBarController for iOS 6 pod 'CYLTabBarController', '~> 1.14.2' 7 - Homepage: https://github.com/ChenYilong/CYLTabBarController 8 - Source: https://github.com/ChenYilong/CYLTabBarController.git 9 - Versions: 1.14.2, 1.14.1, 1.14.0, 1.13.2, 1.13.1, 1.13.0, 1.12.1, 1.12.0, 10 1.11.0, 1.10.0, 1.9.0, 1.8.0, 1.7.0, 1.6.7, 1.6.6, 1.6.5, 1.6.4, 1.6.3, 11 1.6.2, 1.6.1, 1.6.0, 1.5.6, 1.5.5, 1.5.4, 1.5.3, 1.5.2, 1.5.1, 1.5.0, 1.4.5, 12 1.4.4, 1.4.3, 1.4.2, 1.4.1, 1.4.0, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.9, 1.2.8, 13 1.2.7, 1.2.6, 1.2.5, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.1, 1.1.0, 1.0.9, 14 1.0.7, 1.0.6, 1.0.5, 1.0.4, 1.0.3, 1.0.2, 1.0.1, 1.0.0 [master repo] 15 16 -> CYLTabBarController-JDBR (0.0.1) 17 Highly customizable tabBar and tabBarController for iOS 18 pod 'CYLTabBarController-JDBR', '~> 0.0.1' 19 - Homepage: https://github.com/jidibingren/CYLTabBarController 20 - Source: https://github.com/jidibingren/CYLTabBarController.git 21 - Versions: 0.0.1 [master repo] 22 (END)
最后是直接執行的pod update
然后就下載pod 庫(CYLTabBarController)成功了

1 wangwang:WWCopyHomeWorkBox wangyongwangyongwang$ pod update 2 Update all pods 3 Updating local specs repositories 4 $ /usr/local/bin/git -C /Users/wangyongwangyongwang/.cocoapods/repos/master 5 fetch origin --progress 6 remote: Counting objects: 30286, done. 7 remote: Compressing objects: 100% (428/428), done. 8 remote: Total 30286 (delta 10941), reused 11002 (delta 10785), pack-reused 19046 9 Receiving objects: 100% (30286/30286), 3.26 MiB | 1.72 MiB/s, done. 10 Resolving deltas: 100% (20275/20275), completed with 3295 local objects. 11 From https://github.com/CocoaPods/Specs 12 e1a2033..e327ca5 master -> origin/master 13 $ /usr/local/bin/git -C /Users/wangyongwangyongwang/.cocoapods/repos/master 14 rev-parse --abbrev-ref HEAD 15 master 16 $ /usr/local/bin/git -C /Users/wangyongwangyongwang/.cocoapods/repos/master 17 reset --hard origin/master 18 Checking out files: 100% (269710/269710), done. 19 HEAD is now at e327ca5 [Add] OptimizelySDKUserProfileService 1.5.0-RC 20 warning: inexact rename detection was skipped due to too many files. 21 22 CocoaPods 1.4.0.beta.2 is available. 23 To update use: `gem install cocoapods --pre` 24 [!] This is a test version we'd love you to try. 25 26 For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.4.0.beta.2 27 28 Analyzing dependencies 29 Downloading dependencies 30 Installing CYLTabBarController (1.14.2) 31 Generating Pods project 32 Integrating client project 33 34 [!] Please close any current Xcode sessions and use `WWCopyHomeWorkBox.xcworkspace` for this project from now on. 35 Sending stats 36 Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
先寫到這么多,以后再更新;
如有問題,敬請指正;
如需轉載,請注明出處,謝謝!