升级CocoaPods 1.0问题解决汇总

昨天晚上升级了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, 就能编译通过了。效果如下

Edhiha

这次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/

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

offbye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值