Skip to content

Instantly share code, notes, and snippets.

@modeswitch
Last active June 19, 2020 17:16
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save modeswitch/114c9bd55d800df242a2 to your computer and use it in GitHub Desktop.
Save modeswitch/114c9bd55d800df242a2 to your computer and use it in GitHub Desktop.
Building Node.js for Anddoid

Before you begin

Make sure you have adb installed and that it works. Test this by connecting your phone and running adb devices. In order to proceed past the build stage, your device must be rooted. The device I used is running Cyanogenmod with root enabled for both apps and adb.

Build

Fetch the Android NDK

You'll need to get the Android NDK. I used r8e, which you can get from here: http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86.tar.bz2. Make sure you get the x86 version, as the x86_64 version will not help you. Let's call the path where you unpack this NDK_PATH.

Clone the Node.js source

    git clone https://github.com/joyent/node.git

We'll refer to the local path as NODE_SOURCE.

Workaround for ARM

Apply the following changes (either by hand or using patch):

diff --git a/common.gypi b/common.gypi
index 42ab572..48334de 100644
--- a/common.gypi
+++ b/common.gypi
@@ -10,7 +10,8 @@
     'msvs_multi_core_compile': '0',  # we do enable multicore compiles, but not using the V8 way
     'gcc_version%': 'unknown',
     'clang%': 0,
-    'python%': 'python',
+    'python%': 'python2',
+    'arm_version%': 7,
 
     # Enable V8's post-mortem debugging only on unix flavors.
     'conditions': [

Configure the build

    ./android-configure NDK_PATH

Build Node.js

    make

You can find the binary image at NODE_SOURCE/out/Release/node. This is the file you will copy to your Android device.

Run

At this point, you have a binary node that will run on your Android device. There are a few steps involved in getting this file to your device.

Push node to your device

With your device connected to your computer, run

    adb push NODE_SOURCE/out/Release/node /sdcard/
    adb shell
    su
    mount -o remount,rw /
    cp /sdcard/node /sbin
    chmod 755 /sbin/node
    chmod 755 /sbin

Run node

    node
@wallydz
Copy link

wallydz commented May 26, 2014

https://github.com/mNodeJS/node-android you are all welcome to make it better code

@michael-ts
Copy link

I am looking at the possibility of compiling node.js for Android so I can embed node.js in my app, in order to avoid the need to port a large codebase from node.js/javascript to Android/Java. What I'm not following is why the device needs to be rooted (not an option for embedding it in an app) or how this approach fits into the notion of embedding node.js directly in an app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment