Search code examples
iosrubyrubygemsrubymotionkindle

Can I use kindle-highlights gem with RubyMotion


I'm trying to use kindle-highlights gem in RubyMotion. I found motion-bundler, that should help me bring these two together.

According to FAQ from motion-bundler, not every gem will work.

Can I use every random Ruby gem available?

Unfortunately, no. You can only use Ruby gems which do not require libraries (e.g. psych.bundle) and do not use string evaluation at runtime (for instance using class_eval with a String).

If I'm trying to use kindle-higlights I get the uninitialized constant error:

(main)> 2017-02-14 10:13:41.606 HelloMotion[60710:1987881] app_delegate.rb:26:in `application:didFinishLaunchingWithOptions:': uninitialized constant AppDelegate::KindleHighlights (NameError) 2017-02-14 10:13:41.610 HelloMotion[60710:1987881] *** Terminating app due to uncaught exception 'NameError', reason: 'app_delegate.rb:26:in `application:didFinishLaunchingWithOptions:': uninitialized constant AppDelegate::KindleHighlights (NameError)

So what i want to know is:

  • Can I use this gem?
  • Is this the error I should expect, if it is not meant to be?
  • Does "do not require libraries" mean, any library or just some, that kindle-highlights is using?
  • Any suggestions on how to proceed?

Solution

  • Couple of things:

    • Only gems that support Ruby 1.9 will work RubyMotion does not support newer versions of Ruby.
    • Gems that require a C-extension or depend on a Gem that requires a C-extension will not work
    • Gems with eval will not work

    motion-bundler is still a useful library and should help but the gem you want says it required Ruby 2.1.0, so I don't think it will work. If you want to try to make a gem RubyMotion compatible (without motion-bundler) you can try following this tutorial http://blog.motioninmotion.tv/gems-for-ruby-or-rubymotion/