Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running example code results in network error at RN fetch() #5

Open
aschrijver opened this issue Aug 7, 2017 · 21 comments
Open

Running example code results in network error at RN fetch() #5

aschrijver opened this issue Aug 7, 2017 · 21 comments
Labels

Comments

@aschrijver
Copy link

aschrijver commented Aug 7, 2017

First of all: Thanks for this project!

I am checking out the /example code and when running as described in the README and without modifications I get following error:

TypeError: Network request failed
    at XMLHttpRequest.xhr.onerror (fetch.js:441)
    at XMLHttpRequest.dispatchEvent (event-target.js:172)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:546)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:381)
    at XMLHttpRequest.js:485
    at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
    at MessageQueue.__callFunction (MessageQueue.js:260)
    at MessageQueue.js:101
    at MessageQueue.__guard (MessageQueue.js:228)
    at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:100)

I will look into this further, but maybe there is something obvious I am overlooking..

(Versions: yarn 0.24.6, npm 4.2.0, ubuntu 16.04, (local) node: 7.10.1)

PS I will try again with downgraded node on ubuntu system

@aschrijver
Copy link
Author

Downgrading first to 7.1.0, then to 6.9.1 did not solve the issue

@staltz
Copy link
Owner

staltz commented Aug 7, 2017

Can you try making a release build? (would rule out the case where JS is running on your computer. it would run in the phone)

@staltz staltz added the bug label Aug 7, 2017
@staltz
Copy link
Owner

staltz commented Aug 7, 2017

Oh, and are you running it in an emulator or device? (If device:) Is it 64bit or 32bit (e.g. which arm is it?)

@aschrijver
Copy link
Author

aschrijver commented Aug 8, 2017

I am running in the emulator with a Nexus_5X_API_26_x86(AVD) - 8.0.0

The release build has the same issue I think, but suppresses the error, so nothing happens when clicking link. (have also tried Nexus_4_API_23(AVD) - 6.0 with same result)

But I still have one adb error I can't get rid of (don't know if related to the problem, strange error as I only have one emulator up):

:app:installRelease
Installing APK 'app-release.apk' on 'Nexus_5X_API_26_x86(AVD) - 8.0.0' for app:release
Installed on 1 device.

BUILD SUCCESSFUL

Total time: 11.144 secs
Running adb -s emulator-5554 reverse tcp:8081 tcp:8081
adb server is out of date.  killing...
* daemon started successfully *
error: more than one device/emulator
Could not run adb reverse: Command failed: adb -s emulator-5554 reverse tcp:8081 tcp:8081
Starting the app on emulator-5554 (adb -s emulator-5554 shell am start -n com.example/com.example.MainActivity)...
Starting: Intent { cmp=com.example/.MainActivity }

@staltz
Copy link
Owner

staltz commented Aug 8, 2017

If you have a device, experiment with that. With emulators, I've had issues in the past when it comes to networking.

@aschrijver
Copy link
Author

aschrijver commented Aug 8, 2017

Yes thx, I was about to do that, but just tested with node-on-android on an arm64 emulator. That works, but it has a bit different install process. Will now try real device. Just checking what proc it has (otherwise I need to boot an old phone).

Update: My own phone is 64-bit Samsung A3 (https://en.wikipedia.org/wiki/Samsung_Galaxy_A3_(2015)). Going to look into the drawers for an old phone :)

@aschrijver
Copy link
Author

I just tried a real Samsung S3 Mini, but unfortunately it has the same release build issues as occurred with the emulator.

@aschrijver
Copy link
Author

aschrijver commented Aug 10, 2017

I though this may be the cause: facebook/react-native#15100 (comment)

So I downgraded to 0.45.1 but unfortunately with the same result. Afterwards for good measure I also tested with a Nexus_5X_API_24(AVD) - 7.0 without success.

Probably the node app is not responding. I cannot load the URL from a webview on the device as well.

@aschrijver
Copy link
Author

aschrijver commented Aug 12, 2017

FYI:

I've tried many different ways to get NodeJS running on Android and spent yesterday all-day compiling without success.
I am investigating some viable-seeming approaches to use NodeJS in an android project. I have documented my findings on stackoverflow - Viable options to running NodeJS on Android (Aug 2017). You are mentioned there as well.

@aschrijver
Copy link
Author

aschrijver commented Aug 17, 2017

Hi @staltz

I got it working by refactoring to J2V8:

Steps:

  • clone J2V8
  • python build.py --interfactive (using the not-yet-merged build improvement PR)
  • import j2v8-release.aar in react-native-node (8.7 MB, Node 7.9.0 for me, soon 8.1.2)
  • in react-native-node compile project(':j2v8-release')
  • node application is at android/app/src/main/assets (will refactor this to be ./Background)
  • remove any non-standard RN stuff from the gradle projects

Then RNNodeService.java like this:

(PS You don't need a V8Thread. A normal one will do)

For some reason I had to redefine RNNodeModule.start to have no parameters when called with no parameters from RN, otherwise I ended up with error NativeArgumentsParseException got 0 arguments expected 1. Will look into this later.

I now know much more on J2V8 now (see Viable options to running NodeJS on Android (Aug 2017)) and am convinced that both react-native-node and node-on-android would benefit by using this as a basis to build on further. It would not add any overhead in the way the project is working now, and gives some powerful options in e.g. communicating between RN and Node.

I will keep you posted on more findings.

@aschrijver
Copy link
Author

aschrijver commented Aug 19, 2017

One thing not working well yet in above setup is starting and stopping the Service in the case where the Node app is long-running express webserver (haven't tested with original react-native-node, may be an issue as well). This leads to crashes in the app.

Update I am going to refactor to a bound foreground sticky Service (running always independent of app), with NodeJS on its own thread.

@erikdung
Copy link

Any progress here?

@aschrijver
Copy link
Author

This is current status: eclipsesource/J2V8#332
May be solved when J2V8 is ready to build Node 8.4.0 (which is almost)

@erikdung
Copy link

No progress?

@aschrijver
Copy link
Author

@erikdung i managed to get the whole react - node thing working with a modified version of this project that uses J2V8 instead

with the new docker build system in J2V8 this was quite easy to get working.. in fact i would advise @staltz to build this project on top of J2V8, not reinventing the wheel and join forces on making that core module better instead

having said that, on the whole node-on-android concept i found there where problems stopping and starting the service thread running node, leading to crashes of the app

unfortunately i do not have time now to investigate further, as i am working on innercircles, a tech initiative and movement for people who care :)

@staltz
Copy link
Owner

staltz commented Sep 27, 2017

@aschrijver thanks for all this investigation, I think you have a very good point about J2V8, and I'll give it a try soon enough. I'll comment back on this thread later.

@aschrijver
Copy link
Author

that would be cool! i'll jump back to node on android as soon as i have time again..

ps. in the J2V8 project we discussed some interesting ideas to grow the project, make it a solid base for any V8 on android.. the discussion is a bit silent now, but should've blow some more steam into that: eclipsesource/J2V8#335

@p30arena
Copy link

p30arena commented Nov 3, 2017

@staltz
This is what I get on a
platform 23
x86 emulator:

[1]: syntax error: '☺t⌂544O☺☻♣4' unexpected

@p30arena
Copy link

p30arena commented Nov 3, 2017

The NodeJS Binary Included won't work because it is compiled for arm-v7 not x86

@p30arena
Copy link

p30arena commented Nov 4, 2017

I've created an issue on NodeBase repo, asking for compiling instructions

dna2github/NodeBase#5

does anyone have knowledge on how to patch and compile nodejs for Android?
_

@aschrijver
Copy link
Author

@p30arena I wrote something here: https://stackoverflow.com/a/45649995/8295283
and kept track of compilation stuffz here: nodejs/node#14783

hope this helps you a bit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants