HipByte / Flow

Cross-platform libraries for RubyMotion
BSD 2-Clause "Simplified" License
141 stars 29 forks source link

Uninitialized constant error when reference module or class #7

Closed jlmuir closed 8 years ago

jlmuir commented 8 years ago

I'm getting an "uninitialize constant" error when I reference a Flow module or class.

For example, I clone the Flow repo, build the gem with rake gem, and install it. I create an app with motion create --template=flow Hello. I then add one line to the application:didFinishLaunchingWithOptions: method in app/ios/app_delegate.rb:

Store['test'] = 123

When I try to build and run the app, though, it immediately terminates with an uninitialized constant error for AppDelegate::Store, so it seems it doesn't know about the Store class from Flow:

$ rake ios:simulator
       Build build/ios/iPhoneSimulator-9.2-Development
      Create build/ios/iPhoneSimulator-9.2-Development/Hello.app/Info.plist
    Simulate build/ios/iPhoneSimulator-9.2-Development/Hello.app
  *** Starting simulator
  2016-03-14 15:58:52.041 Hello[62268:27772307] app_delegate.rb:9:in `application:didFinishLaunchingWithOptions:': uninitialized constant AppDelegate::Store (NameError)

What am I doing wrong?

I'm using RubyMotion 4.9 on OS X El Capitan.

Thanks!

hboon commented 8 years ago

Do you have the latest version (0.2)?

jlmuir commented 8 years ago

Yes:

$ gem list | grep motion-flow
motion-flow (0.2)
jlmuir commented 8 years ago

OK, I got it working for an iOS project! For an iOS project, the problem is that the docs assume I have the bundler gem installed since they say to add gem lines to Gemfile.

Going back to what I initially reported using the RubyMotion flow template, the created project actually has no targets:

$ motion create --template=flow Hello
    Create Hello
    Create Hello/app/android/main_activity.rb
    Create Hello/app/ios/app_delegate.rb
    Create Hello/config/android.rb
    Create Hello/config/ios.rb
    Create Hello/config/osx.rb
    Create Hello/Gemfile
    Create Hello/Rakefile
$ cd Hello
$ rake -T
$

So, maybe that's not ready yet, or maybe I have to change something to get targets. I don't know how I had targets before; maybe I never did and really just made a mistake and got it mixed up with a RubyMotion ios template project. So, scratch the claim that I'm using a flow template project.

I switched to just using an ios template project:

$ motion create Hello
    Create Hello
    Create Hello/.gitignore
    Create Hello/app/app_delegate.rb
    Create Hello/Gemfile
    Create Hello/Rakefile
    Create Hello/resources/Default-568h@2x.png
    Create Hello/resources/Default-667h@2x.png
    Create Hello/resources/Default-736h@3x.png
    Create Hello/spec/main_spec.rb
$ cd Hello

I add the following line to Gemfile:

gem 'motion-flow'

I add the following line to the application:didFinishLaunchingWithOptions: method in app/app_delegate.rb:

Store['test'] = 123

I build it with rake and get the "uninitialized constant AppDelegate::Store (NameError)" error.

I then tried removing gem 'motion-flow' from Gemfile and adding the following line after require 'motion/project/template/ios' in Rakefile:

require 'motion-flow'

I build and run it with rake and it works!

So, the problem is that the docs assume I have the bundler gem installed when I don't. If I revert my change to Rakefile, install the bunder gem with gem install bundler, build and run with rake, then it works with gem 'motion-flow' in Gemfile.

hboon commented 8 years ago

Hmm.. I tried motion create --template=flow Hello and it worked for me. But glad you figured it out though!

jlmuir commented 8 years ago

It's a Bundler dependency issue again! If I have the bundler gem installed before I run motion create --template=flow Hello, then rake -T reports lots of targets. But if I do not have the bunder gem installed and run motion create --template=flow Hello, then rake -T reports no targets.

jlmuir commented 8 years ago

I think Flow needs to be clear on its prerequisites. If it requires Bundler to work, then this needs to be documented (and probably asserted in code). If it doesn't, then obviously it needs to be able to work when Bundler is not installed.