关闭

升级CocoaPods 1.0.0问题解决汇总

3186人阅读 评论(0) 收藏 举报

昨天晚上升级了CocosPads1.0, 只是安装成功了,现在项目里面运行pod install又发现了几个问题,昨天折腾的太晚了。今天继续折腾吧。
今天终于彻底搞定了CocosPods1.0,包括安装,运行和一个开源项目PodFile的1.0升级。
<!-- more -->
运行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了。



文/offbye(简书作者)
原文链接:http://www.jianshu.com/p/a45b8b708ecb
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:29367次
    • 积分:713
    • 等级:
    • 排名:千里之外
    • 原创:42篇
    • 转载:11篇
    • 译文:0篇
    • 评论:6条
    文章分类
    最新评论