Search code examples
rubyrubymotioncocoapods

Error on require 'motion-cocoapods' with RubyMotion


I just got Ruby motion, and I wanted to try out Cocoapods. I installed it just as it asks on the website:

http://www.rubymotion.com/developer-center/articles/cocoapods/

I add

require 'motion-cocoapods' to my simple 'Hello' project. And I get this error when trying to rake it:

rake aborted! Unable to activate cocoapods-0.16.1, because rake-10.0.3 conflicts with rake (~> 0.9.4)

I guess this has something to do with my version of rake, but I have no idea what I need to do to fix this problem. Please help!


Solution

  • This is caused by having a version of rake newer than 0.9.x installed. When you just run rake, it loads up the newest version (10.0.3 in your case). Then, when the cocoapod gem tries to load, it tries to activate rake 0.9.x and fails (the ~> 0.9.4 means that it will accept any version starting with 0.9.).

    One solution would be to completely remove the rake gem and install the 0.9.4 version explicitly:

    gem uninstall rake
    gem install rake --version '0.9.6'
    

    However, this could become an issue if you have any other projects that require a newer version of rake. A better solution would be to use Bundler:

    gem install bundler
    

    Create a Gemfile in your project folder containing:

    source :rubygems
    gem 'rake'
    gem 'motion-cocoapods'
    

    Add the following to Rakefile, immediately under the require 'motion/project' line:

    require 'bundler'
    Bundler.require
    

    Then run bundle install from the console. This will lock this specific project on rake 0.9.6. The only catch is that you'll probably need to prefix all of your rake commands with bundle exec.