Skip to content

Instantly share code, notes, and snippets.

@psema4
Forked from modeswitch/gist:114c9bd55d800df242a2
Created August 26, 2014 15:19
Show Gist options
  • Save psema4/e5e53f63c4dd94ad57d9 to your computer and use it in GitHub Desktop.
Save psema4/e5e53f63c4dd94ad57d9 to your computer and use it in GitHub Desktop.

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
@psema4
Copy link
Author

psema4 commented Aug 26, 2014

Found in discussion about node-webkit for Android

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