Sunday 20 May 2018

how to run node.js on Android

I mainly use node.js since one year ago at work, and I really like it.
On my work project, I have to create a system which uses socket.io, but I don't have enough time to re-create a system using Android Java.
But I finally figure out how to run node.js on Android.

* This is really advanced topic, so I don't aim for Android beginners. Just for my memo.


1. Rooted your Android


First of all, you have to obtain root permission of your Android.
There are many ways and it's depends on your Android.
Ask to google.

2. Install Debian kit for Android


Debian kit for Android is really awesome tool.
You can install Debian onto your Android.
Download from Google Play store, then follow the instruction.

Debian kit for Android
https://play.google.com/store/apps/details?id=org.dyndns.sven_ola.debian_kit&hl=en

Instruction
http://sven-ola.dyndns.org/repo/debian-kit-en.html

$> cd /data/local/tmp
$> wget http://sven-ola.dyndns.org/repo/debian-kit-1-5.shar
$> sh debian-*
...
... (after the set up)
...
$> deb  // start debian
#> apt-get update
#> apt-get upgrade
#> apt-get install andromize
#> apt-get install sudo
...
... (install another packages if you want)
...

3. Install node.js


Before install node.js, you also need couple of debain packages.
#> apt-get install openssl build-essential python libssl-dev git-core
To install node.js for Debian, you might need to compile node.js from source code. 
#> cd /data/local/tmp
#> wget http://nodejs.org/dist/node-latest.tar.gz
#> tar zxf node-latest.tar.gz
#> cd node*
#> ./configure
#> make
#> make install

If your Android uses ARM architecture, you might be get couple of errors.
To prevent these, add couple of parameters.
#> ./configure --without-snapshot --dest-cpu=arm --dest-os=linux

Snapshot is a technology to run node.js quickly on V8 engine.
But there are bugs for ARM architecture, so you should disable snapshot.
http://stackoverflow.com/questions/16628118/node-js-source-code-build-giving-segmentation-fault-on-arm#16789296

Also you might face an error with "For thumb inter-working we require an architecture which supports blx".
Then get rid of the error code in the macro.
It doesn't affect (at least for me)

HOW TO INSTALL NODE.JS 0.8 ON ARM BASED SBC FOX BOARD G20 > 
STEP 8: CUSTOMIZE MACRO-ASSEMBLER-ARM.CC
http://www.yoovant.com/how-install-node-js-0-8-arm-based-sbc-fox-board-g20/

Congratulation!

Now node.js should run on your Android.

#> node -e "console.log('Hello Node.js on Android')"

0 comments: