rubymotion-community / afmotion

AFMotion is a thin RubyMotion wrapper for AFNetworking
Other
215 stars 46 forks source link

uninitialized constant AFMotion::HTTP::AFFormURLParameterEncoding #18

Closed holgersindbaek closed 11 years ago

holgersindbaek commented 11 years ago

I'm getting this error in my project. I think it is the same error as this one - https://github.com/clayallsopp/afmotion/issues/10.

If I run the sample project, then I can use afmotion with no problem, but it doesn't work in my project. I don't know if it's a gem conflict or what it is, but I really hope there's some sort of solution to this problem.

This is the error I get:

2013-06-21 16:32:50.736 Uninkd Previewer[39862:c07] http.rb:37:in `parameter_encoding': uninitialized constant AFMotion::HTTP::AFFormURLParameterEncoding (NameError)
  from layout.rb:175:in `layout:'
  from teacup_controller.rb:101:in `teacupDidLoad'
  from ui_view_controller.rb:6:in `viewDidLoad'
  from intro_controller.rb:45:in `viewDidLoad'
  from layout.rb:175:in `layout:'
  from teacup_controller.rb:101:in `teacupDidLoad'
  from ui_view_controller.rb:6:in `viewDidLoad'
  from root_controller.rb:17:in `viewDidLoad'
  from app_delegate.rb:18:in `application:didFinishLaunchingWithOptions:'
2013-06-21 16:32:50.738 Uninkd Previewer[39862:c07] *** Terminating app due to uncaught exception 'NameError', reason: 'http.rb:37:in `parameter_encoding': uninitialized constant AFMotion::HTTP::AFFormURLParameterEncoding (NameError)
  from layout.rb:175:in `layout:'
  from teacup_controller.rb:101:in `teacupDidLoad'
  from ui_view_controller.rb:6:in `viewDidLoad'
  from intro_controller.rb:45:in `viewDidLoad'
  from layout.rb:175:in `layout:'
  from teacup_controller.rb:101:in `teacupDidLoad'
  from ui_view_controller.rb:6:in `viewDidLoad'
  from root_controller.rb:17:in `viewDidLoad'
  from app_delegate.rb:18:in `application:didFinishLaunchingWithOptions:'

Gemfile:

# A sample Gemfile
source "https://rubygems.org"

gem "afmotion"
gem "teacup"
gem "sugarcube"
gem "sweettea"
gem 'bubble-wrap'
# gem "motion-awesome" # now handled by sugarcube-awesome
gem "geomotion"
gem "motion-schemes"
# gem "motion-cocoapods"
#gem "motion-xray"
# gem "motion-rubberstamp"#, :git => "git@github.com:IconoclastLabs/motion-rubberstamp.git"
group :development do
  gem "awesome_print_motion"
end

Rakefile:

# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'

# Require bundler
require 'bundler'
Bundler.require

# Require wrappers
# require 'rubygems'
# require 'motion-schemes'
# require 'motion-cocoapods'
require 'afmotion'
# require 'sugarcube'
# require 'sugarcube-568'
# require 'bubble-wrap'
# require 'teacup'
# require 'geomotion'

# Create new properties 
require './lib/app_properties'
previewer_props = AppProperties.new(name: 'Uninkd Previewer', path_name: '1_Previewer', development_license: 'iPhone Distribution: Uninkd, LLC.', distribution_license: 'iPhone Developer: Per Hakansson (JK2VU4L6Y2)', id: 'previewer')

Motion::Project::App.setup do |app|
  app.name =                            previewer_props.name
  app.version =                         previewer_props.version
  app.short_version =                   previewer_props.short_version

  app.identifier =                      previewer_props.identifier
  app.resources_dirs =                  previewer_props.resources_dirs

  app.frameworks =                      previewer_props.frameworks
  app.resources_dirs =                  previewer_props.resources_dirs
  app.files +=                          Dir.glob(File.join(app.project_dir, 'lib/**/*.rb'))

  app.deployment_target =               previewer_props.deployment_target
  app.sdk_version =                     previewer_props.sdk_version

  app.icons =                           previewer_props.icons
  app.fonts =                           previewer_props.fonts
  app.prerendered_icon =                previewer_props.prerendered_icon

  app.device_family =                   previewer_props.device_family
  app.interface_orientations =          previewer_props.interface_orientations

  app.info_plist['CFBundleIcons'] =     previewer_props.newsstand_icons
  app.info_plist['UINewsstandApp'] =    previewer_props.newsstand_app
  app.info_plist['UIBackgroundModes'] = previewer_props.background_modes
  app.info_plist['UIStatusBarHidden'] = previewer_props.statusbar_hidden
  app.info_plist['UIStatusBarStyle'] =  previewer_props.statusbar_style

  app.development do
    app.codesign_certificate =          'iPhone Developer: Per Hakansson (JK2VU4L6Y2)'
  end

  app.release do
    # app.codesign_certificate = 'iPhone Distribution: Your Name Here'
    # app.provisioning_profile = '/path/to/your/distribution_provisioning_profile.mobileprovision'
  end

  app.pods do
    pod 'QBFlatButton', :git => 'https://github.com/holgersindbaek/QBFlatButton.git', :branch => 'master'
    # pod 'QBFlatButton', :path => '~/Projects/*Defaults/Misc/Cocoapods/QBFlatButton', :branch => 'master'
    pod 'SKInnerShadowLayer', '~> 1.1'
    # pod 'SSToolkit', '~> 1.0.4'
    pod 'SSTextField', :path => '~/Projects/*Defaults/Misc/Cocoapods/SSTextField', :branch => 'master'
    pod 'DTCoreText', '~> 1.5.3'
    pod 'MSLabel', '~> 0.0.1'
    pod 'AFNetworking'
    pod 'Reachability'
    pod 'BPStatusBar', :git => 'https://github.com/holgersindbaek/BPStatusBar.git', :branch => 'master'
  end
end

Motion::Project::App.scheme(:Made) do |app|
end

intro_controller.rb:

class IntroController < UIViewController
  include BaseHelper
  include IntroHelper
  stylesheet :intro

  # Layout code via teacup
  layout :intro do
    @container = subview(UIView, :container) do
      @signup_label = subview(MSLabel, :signup_label)
      @signup_button = button(:signup_button, {title: 'PREVIEW'})
      @signup_input = input(:signup_input, {delegate: self})
    end

    AFMotion::HTTP.get("http://google.com") do |result|
      p result.body
    end

    # @signup_input.becomeFirstResponder
    @signup_button.when(UIControlEventTouchUpInside) do
      if internet_connected?
        BPStatusBar.showErrorWithStatus("No Connection")
        # return
      end

      BW::HTTP.get("http://#{@signup_input.text}.uninkd.com/existence.plist") do |response|
        if response.ok?
          plist = response.body.to_s.propertyListFromStringsFileFormat
          p plist[:Cover]
        else

        end
      end
    end

    @signup_input.on :editing_did_begin do
      keyboard_height = Device.ipad? ? 264 : 216
      @container.move_to([20, (Device.screen.height-keyboard_height)/2-(@container.frame.size.height/2)], duration: 0.25)
    end
  end  

  def layoutDidLoad
  end

  def viewDidLoad
    super
  end

end
clayallsopp commented 11 years ago

Does declaring app.detect_dependencies = false fix the error?

holgersindbaek commented 11 years ago

That seems to break other stuff, like including modules in files. What do you think I should do?

All the best

Holger Sindbaek Holgersindbaek.com (http://Holgersindbaek.com)

Co-founder Uninkd.com (http://Uninkd.com) Meer.li (http://Meer.li)

On Friday, June 21, 2013 at 4:41 PM, Clay Allsopp wrote:

Does declaring app.detect_dependencies = false fix the error?

— Reply to this email directly or view it on GitHub (https://github.com/clayallsopp/afmotion/issues/18#issuecomment-19839498).

holgersindbaek commented 11 years ago

Should I not detect dependencies and do it all manually with your other gem (motion require, I think it was called)?

holgersindbaek commented 11 years ago

@clayallsopp What do you say Clay. How can I help troubleshoot this one?

clayallsopp commented 11 years ago

I've added support for a new RubyMotion feature with 3a4883c33161f5f7a3d459aea34d90eb7b514e9e; this should make it work without a global detect_dependencies = false.

This feature isn't pushed to a general release yet, so you'll have to clone the RubyMotion master branch and set a RUBYMOTION_LIB environment variable:

$ cd YourPorject
$ RUBYMOTION_LIB=~/your_git_repos/RubyMotion/lib rake

let me know how it goes

holgersindbaek commented 11 years ago

I'm ended up installing from this master git branch and things worked. I didn't have to set the environment variable.

Thanks for the help.

I am getting a funny warning when I bundle though, but things are working in spite of it:

 https://github.com/clayallsopp/afmotion.git (at master) is not checked out. Please run `bundle install`

I've run 'bundle install' a hundred times, but things don't seem to be working.

VGraupera commented 11 years ago

Im getting a similar

uninitialized constant AFMotion::JSON::AFJSONParameterEncoding (NameError)

ive tried app.detect_dependencies = false and that does not seem to fix it

matthewsinclair commented 11 years ago

Are you sure you don't have an explicit dependency that is being missed? I had a similar problem with my code interacting with Formotion recently (when I was building a gem to be included in another project), and I ended up having to add this kind of thing to the top-level include file for the gem:

my-gem/lib/my-gem.rb

require "my-gem/version" require 'bubble-wrap/all' require 'cocoapods' require 'motion-cocoapods' require 'formotion' require 'elevate' require 'motion-pixate' require 'ib'

unless defined?(Motion::Project::Config) raise "This file must be required within a RubyMotion project Rakefile." end

Motion::Project::App.setup do |app|

app.resourcesdirs << File.join(File.dirname(FILE), '../resources') app.files += Dir.glob(File.join(File.dirname(FILE), 'my-gem/*/_.rb'))

custom_dependencies = [ [ 'my-gem/dir/dir/depends_on_string_row1.rb', 'formotion/row_type/string_row.rb' ], [ 'my-gem/dir/dir/depends_on_string_row2.rb', 'formotion/row_type/string_row.rb' ] ] custom_dependencies.each do |dep| from = app.files.select {|f| f.match(dep[0]) }.first to = app.files.select {|f| f.match(dep[1]) }.first app.files_dependencies(from => to) end

end

This was necessary because RM compiles the file in "operating system" order, and if you have a class that depends on something in an included gem, you've got to make sure that your class gets included and compiled after the dependent file form the gem.

Whenever I have an explicit dependency in my project, I just add it to the custom_dependencies array as per the above.

Which works a treat. Unless you spell the filename incorrectly … :)

On 21/08/2013, at 10:04 AM, Vidal Graupera notifications@github.com wrote:

Im getting a similar

uninitialized constant AFMotion::JSON::AFJSONParameterEncoding (NameError)

ive tried app.detect_dependencies = false and that does not seem to fix it

— Reply to this email directly or view it on GitHub.

yestoall commented 11 years ago

i'm having the same problem now... since yesterday :(

uninitialized constant AFMotion::JSON::AFJSONParameterEncoding (NameError)

VGraupera commented 11 years ago

I wonder if this is a bug with rubymotion itself...?

I've actually stopped using afmotion for now and switched to BW:HTTP because of random errors like these that I dont know how to resolve.

yestoall commented 11 years ago

i think is not a AFMotion problem, in other projects it works perfect.

maybe is something about cache and RM compilations issues, because i just clone my own github repository again and now is working ... like magic.

i can't really understand why, but it's ok again :$

VGraupera commented 11 years ago

i agree with u. i also think its probably not anything to due with afmotion itself, but when it stops working randomly due to these constants not being found in RM its hard to continue working

clayallsopp commented 11 years ago

For any folks having this issue, please try using gem "afmotion", "~> 2.0.0.rc1": http://rubygems.org/gems/afmotion/versions/2.0.0.rc1

Open a new issue if that still causes problems

yestoall commented 11 years ago

in my first compilation with 2.0.0.rc1: uninitialized constant AFMotion::ClientDSL::AFJSONRequestSerializer (NameError)

On Wed, Oct 23, 2013 at 1:27 AM, Clay Allsopp notifications@github.comwrote:

For any folks having this issue, please try using gem "afmotion", "~> 2.0.0.rc1": http://rubygems.org/gems/afmotion/versions/2.0.0.rc1

Open a new issue if that still causes problems

— Reply to this email directly or view it on GitHubhttps://github.com/usepropeller/afmotion/issues/18#issuecomment-26863422 .

nacho

clayallsopp commented 11 years ago
  1. can you confirm in your Podfile.lock that AFNetworking 2.0 is being loaded, not AFNetworking 1.x?
  2. can you try doing rake clean:all, rake pod:install, rake, and seeing if the error persists?

On Wed, Oct 23, 2013 at 3:22 AM, nacho rapallo notifications@github.comwrote:

in my first compilation with 2.0.0.rc1: uninitialized constant AFMotion::ClientDSL::AFJSONRequestSerializer (NameError)

On Wed, Oct 23, 2013 at 1:27 AM, Clay Allsopp notifications@github.comwrote:

For any folks having this issue, please try using gem "afmotion", "~> 2.0.0.rc1": http://rubygems.org/gems/afmotion/versions/2.0.0.rc1

Open a new issue if that still causes problems

— Reply to this email directly or view it on GitHub< https://github.com/usepropeller/afmotion/issues/18#issuecomment-26863422> .

nacho

— Reply to this email directly or view it on GitHubhttps://github.com/usepropeller/afmotion/issues/18#issuecomment-26894210 .

yestoall commented 11 years ago

now it's solved and working. i had a problem with my configuration and cache compilation.

thanks for your work ;)

On Wed, Oct 23, 2013 at 7:00 PM, Clay Allsopp notifications@github.comwrote:

  1. can you confirm in your Podfile.lock that AFNetworking 2.0 is being loaded, not AFNetworking 1.x?
  2. can you try doing rake clean:all, rake pod:install, rake, and seeing if the error persists?

On Wed, Oct 23, 2013 at 3:22 AM, nacho rapallo notifications@github.comwrote:

in my first compilation with 2.0.0.rc1: uninitialized constant AFMotion::ClientDSL::AFJSONRequestSerializer (NameError)

On Wed, Oct 23, 2013 at 1:27 AM, Clay Allsopp notifications@github.comwrote:

For any folks having this issue, please try using gem "afmotion", "~> 2.0.0.rc1": http://rubygems.org/gems/afmotion/versions/2.0.0.rc1

Open a new issue if that still causes problems

— Reply to this email directly or view it on GitHub< https://github.com/usepropeller/afmotion/issues/18#issuecomment-26863422>

.

nacho

— Reply to this email directly or view it on GitHub< https://github.com/usepropeller/afmotion/issues/18#issuecomment-26894210> .

— Reply to this email directly or view it on GitHubhttps://github.com/usepropeller/afmotion/issues/18#issuecomment-26922932 .

nacho