您的位置:首页 > 其它

升级CocoaPods 1.0问题解决汇总

2016-05-28 22:47 519 查看
昨天晚上升级了CocosPads1.0, 只是安装成功了,现在项目里面运行pod install又发现了几个问题,昨天折腾的太晚了。今天继续折腾吧。

今天终于彻底搞定了CocosPods1.0,包括安装,运行和一个开源项目PodFile的1.0升级。

运行
pod install
时发现CocoaPods 提示有1.0版本了,于是打算升级一下。

CocoaPods 1.0.0 is available.

To update use:
gem install cocoapods


结果就出现了下面的错误,分析了下原因是/usr/bin/xcodeproj目录路径错了,网上搜了下解决问题,使用
sudo gem install -n /usr/local/bin cocoapods --pre
命令顺利安装成功。

$ sudo gem install cocoapods
ERROR:  While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj

$ ls -al /usr/bin/xcodeproj
ls: cannot access /usr/bin/xcodeproj: No such file or directory
$ sudo gem install -n /usr/local/bin cocoapods --pre
Successfully installed xcodeproj-1.0.0
Fetching: molinillo-0.4.5.gem (100%)
Successfully installed molinillo-0.4.5
Fetching: cocoapods-try-1.0.0.gem (100%)
Successfully installed cocoapods-try-1.0.0


在项目下运行
pod install
报错了:

od install
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/lib/cocoapods/sources_manager.rb:159:in `<module:SourcesManagerMissingConstant>': uninitialized constant Pod::SourcesManagerMissingConstant::Set (NameError)
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/lib/cocoapods/sources_manager.rb:158:in `<module:Pod>'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/lib/cocoapods/sources_manager.rb:3:in `<top (required)>'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/lib/cocoapods/core_overrides.rb:1:in `<top (required)>'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/lib/cocoapods.rb:71:in `<module:Pod>'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/lib/cocoapods.rb:17:in `<top (required)>'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/bin/pod:36:in `<top (required)>'
from /usr/local/bin/pod:23:in `load'
from /usr/local/bin/pod:23:in `<main>'


网上搜了下,发现这个issue已经close了,但好像没有更新啊,https://github.com/CocoaPods/CocoaPods/pull/5288

只好自己看代码修改一下:

修改 /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.0/lib/cocoapods/sources_manager.rb

在第二行增加

require 'set'


保存文件,需要输入密码的。

继续运行
pod install
, 结果又报下面的错误:

edhita $ pod install
Re-creating CocoaPods due to major version update.
[!] `:head` dependencies have been removed. Please use normal external source dependencies (`:git => 'GIT_REPO_URL'`) instead of `:head` for `EDHFontSelector`.


这个看提示应该是个版本兼容问题了,还是先去仔细看看官方的CocoaPods 1.0的release说明吧。

应该是不支持
:head
这个语法了,并且必须有target。

这里有个官方迁移指南

拥抱 CocoaPods 1.0

下面用正在研究的markdown编辑器Edhita的Podfile做个升级的例子吧,

原地址 https://github.com/tnantoka/edhita/blob/master/Podfile

迁移前的代码:

platform :ios, "8.0"

source 'https://github.com/CocoaPods/Specs.git'

pod 'EDHFinder', '~> 0.1'
pod 'EDHFontSelector', :head
pod 'EDHInputAccessoryView', '~> 0.1'
pod 'Google-Mobile-Ads-SDK'
pod 'Colours', '~> 5.5'
pod 'FXForms', '~> 1.2'
pod 'GHMarkdownParser', '~> 0.1'
pod 'VTAcknowledgementsViewController', '~> 0.12'

pod 'Bootstrap', podspec: 'https://raw.githubusercontent.com/tnantoka/podspecs/master/Specs/Bootstrap/Bootstrap.podspec'
pod 'Megrim', podspec: 'https://raw.githubusercontent.com/tnantoka/podspecs/master/Specs/Megrim/Megrim.podspec'
pod 'github-markdown-css', podspec: 'https://raw.githubusercontent.com/tnantoka/podspecs/master/Specs/github-markdown-css/github-markdown-css.podspec'

post_install do |installer|
require 'fileutils'
FileUtils.cp_r('Pods/Target Support Files/Pods/Pods-acknowledgements.plist', 'Edhita/Assets/Pods-acknowledgements.plist')
end


升级到cocosPods 1.0后的代码

platform :ios, "8.0"

source 'https://github.com/CocoaPods/Specs.git'
target 'Edhita'
pod 'EDHFinder', '~> 0.1'
pod 'EDHFontSelector', '~> 0.1'
pod 'EDHInputAccessoryView', '~> 0.1'
pod 'Google-Mobile-Ads-SDK'
pod 'Colours', '~> 5.5'
pod 'FXForms', '~> 1.2'
pod 'GHMarkdownParser', '~> 0.1'
pod 'VTAcknowledgementsViewController', '~> 0.12'

# pod 'Bootstrap', podspec: 'https://raw.githubusercontent.com/tnantoka/podspecs/master/Specs/Bootstrap/Bootstrap.podspec'
# pod 'Megrim', podspec: 'https://raw.githubusercontent.com/tnantoka/podspecs/master/Specs/Megrim/Megrim.podspec'
# pod 'github-markdown-css', podspec: 'https://raw.githubusercontent.com/tnantoka/podspecs/master/Specs/github-markdown-css/github-markdown-css.podspec'

post_install do |installer|
require 'fileutils'
# FileUtils.cp_r('Pods/Target Support Files/Pods-Edhita/Pods-Edhita-acknowledgements.plist', 'Edhita/Assets/Pods-acknowledgements.plist')
end


我偷懒注释了一些不需要的代码,运行
pod install
, Xcode打开Edhita.xcworkspace, 就能编译通过了。效果如下



这次CocoaPods 1.0的升级体验还真是坑啊,经历了4年半的开发才发布1.0版本啊,不知道该说什么好了。

珍爱生命,新项目拥抱Carthage吧。但也不能不用CocoaPods啊,那么多开源项目都用了啊,还是暂时先不要升级1.0了。

[本文独立博客地址](http://www.offbye.com/2016/05/29/%E5%8D%87%E7%BA%A7CocoaPods-1-0-0%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%B1%87%E6%80%BB/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: