There are a bunch of old SO threads dealing with running NodeJS on Android. Most of these are no longer viable (JXCore) and/or provide confusing, outdated, incomplete, or erroneous information.
Therefore I have investigated what seems to be currently (as of August 2017) viable approaches and found three likely candidates.
To decide between them I would like to know:
Viable approaches are:
Besides that I have found a number of related interesting resources:
[NOTE This answer contains findings that were in the original question]
I have investigated the various options a bit more and here are some preliminary findings.
Each of the options uses some form of NodeJS compiled for Android. But to use any option you would probably want to compile to different Node, Android and architecture (x86, ARM, ARM64, etc.) versions.
This is problematic. NodeJS has an
android-configure script, but this results in errors in most combinations I've tried. I created a number of github issues for a working build script. In this issue results are collected:
libnode.a) statically linked in
libj2v8.soworks for 7.x up to
J2V8 is a set of Java bindings for V8. J2V8 focuses on performance and tight integration with V8. [...] [which] forces a more static type system between the JS and Java code, but it also improves the performance since intermediate Objects are not created. [...]
Building J2V8 requires building both the native parts and the Java library (.jar/.aar file). To build the native parts we first build node.js as a library and then statically link J2V8 to that. [...]
For cross-compiling J2V8 uses Docker (android, linux, windows) and Vagrant (macos).
Start a build simply with
python build.py --interactive, select build:
 Docker >> android-x86 >> NODE_ENABLED  Docker >> android-arm >> NODE_ENABLED  Docker >> alpine-linux-x64 >> NODE_ENABLED  Docker >> linux-x64 >> NODE_ENABLED  Docker >> linux-x86 >> NODE_ENABLED  Vagrant >> macosx-x64 >> NODE_ENABLED  Vagrant >> macosx-x86 >> NODE_ENABLED  Native >> windows-x64 >> NODE_ENABLED  Docker >> windows-x64 >> NODE_ENABLED  Vagrant >> windows-x64 >> NODE_ENABLED
Select build steps (or
NodeJS --> CMake --> JNI --> Optimize --> Java/Android --> JUnit
Compiles V8 as shared library
nodejsbuild step cannot build Node shared library (errors), creates static
libnode.ato be linked in
.aarto include as project dependency
Node on android works by running your Node.js inside the android app using a shared library. It then bundles a
WebViewthat hosts your UI code. All UI is just classic html/css/js.
In the node app you can require
node-on-androidto get access to the WebView. You can use this to load an html page in the
node-on-android creator (@mafintosh) this is easier and better than J2V8 as it compiles V8 directly as the real thing.
Servicewith node running in a separate thread
private native void startNode(String... app);shows as error in IDE (but compiles)
arm64architecture (full mobile support planned, or DIY build)
Run a real Node.js process in the background, behind a React Native app.
Using this package you can: run http servers in Android, use Node streams, interface with the filesystem, offload some heavy processing out of the JS thread in React Native, and more! Running the real Node.js in Android, you can do everything that Node.js on desktop can.
Servicewith Node on separate thread)
nodeis compiled/used as application, not an embedded shared lib
RNNodeis available in RN by importing
react-native-nodealso contains CLI that transfers Node code at build time
http://localhost:5000at Node side
7.1.0version (but DIY build newer ones)
My goal is React Native + NodeJS. This is the status of my activities:
react-native-nodedoes compile, but does not operate despite many tries
node-on-androidworks, but node-only app development and 64-bit incompatible with RN
I decided to combine
J2V8 because of:
.aarto be easily included in Gradle
0.46.4 + NodeJS
7.9.0 is now working! See:
My use case: fat client with P2P decentralized networking
I am thinking of a CQRS (command-query-responsibility-segregation) design:
Even after years of people trying to port NodeJS to Android there are still no real good solutions, it is pioneering.
Expect many hurdles and errors as you set up your project and build environment, but once setup you could enjoy the full power of Node on your phone.
As of today (March 2018), there is another viable alternative not yet listed in the current answers: Node.js for Mobile Apps.
Pre-built binaries for the library are available for Android armeabi-v7a, x86, arm64-v8a, x86_64, and for iOS 64-bit.
The core library is a fork of nodejs/node-chakracore, which in turn is fork of nodejs/node. The Android version is pretty much regular Node.js built as a library, with a few portability fixes. The iOS version uses the ChakraCore engine instead of V8 (replacing V8 with ChakraCore is possible thanks to the changes in the nodejs/node-chakracore fork).
More information, including some documentation, is available on the project website.
(Full disclosure: I work for the company that develops Node.js for Mobile Apps.)
Thx for your question. I will do a brief answer in my view.
Not familar with LiquidCore; build micro service especially from url, I think, is to resolve no direct available storage on iOS. react-native-node the Android part is based on NodeBase method and use the prebuilt binary.
At first, I run node in terminal; I find only dev can easily to use it to start js app. My friends and families also wanna some tools for example make water mark on picture in batch. NodeBase is created for them to easy to start/stop app. Then they just need to open browser to use it. My another idea to create NodeBase is that we can build sharable applications that can be shared in the same Wi-Fi. When host starts an app, it can be visited by near people. Then they can work and play together. For example, we play werewolf and when there is no judge, we will start the werewolf app to have a judge for the first round. We can also share files between devices via download/upload.
For me, I can build what I want flexibly for example, I would like to make my Android as a machine learning runner; it can help me run machine learning programs at anytime (with node and python, thus in my another repo: dna2oslab is focus on building binaries) to make use of phone running time.
For you, if wanna port your app in a short time, I recommend 2; if you have time and other resources, 1 is better. 3 if you just make a toy/demo. 4 other is always possible and just do your imagination to create works.
Best wishes, Seven
I tried using J2V8 in my Android Java app to run a JS script via node.js. It fails with this error:
java.lang.UnsupportedOperationException: StartNodeJS Not Supported.
The response from J2V8 was:
"The node wrappers are not available on Android, they are only available on the Desktop platforms (windows, mac, linux). This is the expected behaviour until we have node binaries for Android."
As far as I know, there are no current plans to implement node wrappers for Android.
I am the author of LiquidCore. LiquidCore allows you to use full implementations of Node.js on both Android and iOS (iOS support was just released in version 0.5.0 -- September 2018).
©2020 All rights reserved.