Android PhoneGap and RequireJS

915 views
Skip to first unread message

Aaron

unread,
Mar 26, 2012, 3:57:06 PM3/26/12
to phonegap
Hello,

I'm trying to get RequireJS (v1.0.7) to work with PhoneGap
(v1.5.0), but am running into a predicament using Android. For some
reason, the Android version of cordova.js (cordova-1.5.0.js)
implements it's own require and define methods. This makes it unable
to be used along side with RequireJS and probably other AMD loaders.
I've tried multiple attempts at trying to get them to work together
(inluding renaming cordova's "require" and "define" methods) with no
such luck. Is it possible to get a patch for the Android version to
fix this? I'm not asking for phonegap to be AMD compatible, just not
over-write the standard "require" and "define" methods. I've had no
problems with the IOS version and have yet to try the windows version.

Original RequireJS google group post:
http://groups.google.com/group/requirejs/browse_thread/thread/282a85c5eeed613f/e37063b882a9ff15?lnk=gst&q=phonegap#e37063b882a9ff15

TLDR: PhoneGap has implemented non standard "require" and "define"
methods in the Android version of PhoneGap ("cordova-1.5.0.js") making
it unable to be used with AMD loaders such as RequireJS.

Piotr Walczyszyn

unread,
Mar 27, 2012, 6:30:47 AM3/27/12
to phonegap
I also run into the same problem and I had to revert back my android
project to 1.4.1 version.
I followed recommendation from RequireJS discussion list to initialize
Cordova after RequireJS and to do conditional require,define overrides
but unfortunately the implementation that comes with Cordova is not
compatible with RequireJS.

p.

On Mar 26, 9:57 pm, Aaron <bigred...@gmail.com> wrote:
> Hello,
>
>      I'm trying to getRequireJS(v1.0.7) to work with PhoneGap
> (v1.5.0), but am running into a predicament using Android.  For some
> reason, the Android version of cordova.js (cordova-1.5.0.js)
> implements it's own require and define methods.  This makes it unable
> to be used along side withRequireJSand probably other AMD loaders.
> I've tried multiple attempts at trying to get them to work together
> (inluding renaming cordova's "require" and "define" methods) with no
> such luck.  Is it possible to get a patch for the Android version to
> fix this?  I'm not asking for phonegap to be AMD compatible, just not
> over-write the standard "require" and "define" methods.  I've had no
> problems with the IOS version and have yet to try the windows version.
>
> OriginalRequireJSgoogle group post:http://groups.google.com/group/requirejs/browse_thread/thread/282a85c...

Dewang Shah

unread,
Apr 10, 2012, 9:56:19 AM4/10/12
to phon...@googlegroups.com
Hi Piotr,

Does PhoneGap 1.4.1 work for you? I am using 1.5.0 with a patch from the main branch of 1.6.0 to make sure there is no conflict with the require/depend methods. It all works fine when I try it in a browser and on the Android simulator but when I try to load exactly the same code on an actual phone I get a timeout error from Require.js. I have tried setting the timeout to 30 seconds but it still fails.

Any ideas?

Thanks

Dewang Shah

unread,
Apr 10, 2012, 10:19:39 AM4/10/12
to phon...@googlegroups.com
Sorted. Looks like it was a problem with a Require plugin I was using to load PhoneGap as an AMD module. Changed that to just wrap it myself and it works!
Reply all
Reply to author
Forward
Message has been deleted
0 new messages