升级CocoaPods 1.0.0问题解决汇总

作者: offbye西涛 | 来源:发表于2016-05-29 23:35 被阅读3518次

    昨天晚上升级了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了。

    相关文章

      网友评论

      • qBryant:参考你的文章解决了。。谢谢!👍
      • leisurehuang:如果你的电脑安装了多个版本的Cocoa pods,可以通过pod _0.39.2_ install 的形式选择特定版本来install
      • 朵朵一花浪:麻烦问一下更新到1.0之后,然后在cocoapod install 工程里面找不到头文件了 是什么原因,不是import 找不到,是编译的时候找不到了,这个是什么问题

        朵朵一花浪:@狂奔的泡面 这个问题是要把库重新添加一下就行了
        4bc347552fb5:@Jonny_Lee 解决了吗?我也遇到这个问题
      • 小凡凡520:1.0版本什么时候出来的?
        offbye西涛:@小凡凡520 今年5月

      本文标题:升级CocoaPods 1.0.0问题解决汇总

      本文链接:https://www.haomeiwen.com/subject/ukpqdttx.html