Run Node.js on Android by rewrite Node.js in Java

Overview

node-android

Android CI

Run Node.js on Android by rewrite Node.js in Java with the compatible API.

third-party: libuvpp, libuv-java JNI code by Oracle.

Build

Clone the code, open Android Studio (1.*) and import the project.

For Eclipse ADT user, refer to ADT branch

Javascript code injection

> adb shell am start -a android.intent.action.VIEW -n com.iwebpp.nodeandroid/.MainActivity -e js "var run = function () { return 'hello world'; } run();"

Features

JS runtime

  • Rhino supported
  • Exposed node-android packages: com.iwebpp.node.http, com.iwebpp.node.stream, com.iwebpp.node.net, etc
  • Exposed node-android classes: com.iwebpp.node.EventEmitter2, com.iwebpp.node.Dns, com.iwebpp.node.Url, etc
  • Exposed node-android native context in JS standard scope as NodeCurrentContext alias NCC
  • Exposed Android API: android.util.Log
  • NodeJS compatible internal modules are available in JS standard scope
  • Exposed WebSocket classes: com.iwebpp.wspp.WebSocket, com.iwebpp.wspp.WebSocketServer

JS usage

  • In case Rhino, create class 'MyScript' extends from com.iwebpp.node.js.rhino.Host
  • Implement 'public String content()' in 'MyScript' to return user script
  • Execute JS engine in a separate Java Thread with 'MyScript.execute()'
  • When authoring script, please use NodeCurrentContext(alias NCC) in node-android API
  • JS API usages details

TODO

  • API doc, more demos
  • JS runtime CommonJS/AMD compliance

Support us

  • Welcome contributing on document, codes, tests and issues

### License

(see LICENSE file)

Copyright (c) 2014-present Tom Zhou([email protected])

Comments
  • run JS engine on node-android

    run JS engine on node-android

    some people asked about run overall node.js npm, etc.

    But, Android framework does provide most of device capability. I am still wonder if make sense to run JS engine on JVM.

    enhancement help wanted 
    opened by sequoiar 15
  • Error:Cause: com.android.sdklib.repository.FullRevision,

    Error:Cause: com.android.sdklib.repository.FullRevision,

    Hi, I use Android Studio to create apk file from this source. From some reason, I get Error:Cause: com.android.sdklib.repository.FullRevision, What is the problem? How to fix it?

    Thanks H.L

    opened by Asscobara 3
  • Add `android` module to access its API

    Add `android` module to access its API

    node-android could have its platform specific module, allowing to access Android API like:

    var android = require('android'),
        Canvas = android.graphics.Canvas,
        Service = android.app.Service,
        ViewGroup = android.view.ViewGroup;
        myView = new ViewGroup(context);
    setContentView(myView);
    myView.requestFocus();
    
    opened by aurium 2
  • 'ARMV7A_FILTER' is missing an input or output annotation

    'ARMV7A_FILTER' is missing an input or output annotation

    Hello 👋🏻 am try to compile this project using Android Studio Chipmunk | 2021.2.1 and am getting this error below, how can I solve this ? thanks.

    Some problems were found with the configuration of task ':app:resolveNativeDependencies' (type 'NativeDependenciesResolverTask').

    • In plugin 'android-native-dependencies' type 'com.nabilhachicha.nativedependencies.task.NativeDependenciesResolverTask' property 'ARMV7A_FILTER' is missing an input or output annotation.
    opened by delltrak 1
  • Can't find method com.iwebpp.node.http.http.createServer

    Can't find method com.iwebpp.node.http.http.createServer

    hi, i'm trying to run simply code from the editor:

    var http = require('http'); var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World\n"); }); server.listen(8000);

    but i have error: Can't find method com.iwebpp.node.http.http.createServer Which is strange because i see the method in the code. I do not know what to do. The whole log:

    D/MainActivity( 1240): start test D/dalvikvm( 1240): Trying to load lib /data/app-lib/com.iwebpp.nodeandroid-1/libuvpp-jni.so 0xb1d79098 D/dalvikvm( 1240): Added shared lib /data/app-lib/com.iwebpp.nodeandroid-1/libuvpp-jni.so 0xb1d79098 D/dalvikvm( 1240): No JNI_OnLoad found in /data/app-lib/com.iwebpp.nodeandroid-1/libuvpp-jni.so 0xb1d79098, skipping init D/dalvikvm( 1240): GC_CONCURRENT freed 259K, 9% free 3292K/3612K, paused 4ms+4ms, total 51ms D/dalvikvm( 1240): GC_CONCURRENT freed 226K, 8% free 3501K/3792K, paused 4ms+4ms, total 44ms D/dalvikvm( 1240): GC_CONCURRENT freed 242K, 8% free 3719K/4028K, paused 19ms+15ms, total 77ms D/dalvikvm( 1240): GC_CONCURRENT freed 253K, 7% free 3927K/4208K, paused 4ms+4ms, total 59ms E/RhinoHost( 1240): org.mozilla.javascript.EvaluatorException: Can't find method com.iwebpp.node.http.http.createServer(function). (UserContent#8) W/System.err( 1240): java.lang.Exception: Rhino runtime exception: org.mozilla.javascript.EvaluatorException: Can't find method com.iwebpp.node.http.http.createServer(function). (UserContent#8) W/System.err( 1240): at com.iwebpp.node.js.rhino.Host.execute(Host.java:312) W/System.err( 1240): at com.iwebpp.nodeandroid.MainActivity$2.run(MainActivity.java:202) W/System.err( 1240): at java.lang.Thread.run(Thread.java:841) D/MainActivity( 1240): exit test

    opened by gar1388 1
  • Tests -> Android Unit Tests

    Tests -> Android Unit Tests

    Hi,

    DONE

    I did the following things:

    • added javascript injection ability via adb like this:
    > adb shell am start -a android.intent.action.VIEW -n com.iwebpp.nodeandroid/.MainActivity -e js "var run = function () { return 'hello world'; } run();"
    
    • changed the package name to com.iwebpp.nodeandroid
    • cleaned up the code;
    • converted all the test code into proper unit tests;
    • the MainActivity is now a live Node.js interpreter;
    • added a global js function called "toast", you may guess what it does.

    TODO

    I still want to do the following things:

    • check if all the tests are actually failing or succeeding, since exceptions are being caught like this:
    public void testSomething()
    {
        try
       {
            // something complicated
        }catch (Throwable t)
        {
           // hide the error
        }
        // ... the test succeeds anyhow
    }
    
    • add an Adapter to the interactive Node.js Activity for the rhino output, like RunScript;
    • add a DrawerLayout; upgrade ActionBar to Toolbar/App bar (api 21);
    • tweak Host, so multiple nodes or a singleton can be spawned (e.g. multiple websocket clients on one machine... etc. one websocket server...), right now a new Host (rhino context) is created for each run.

    In the future I would like to run feross / webtorrent on this project.

    Merge it if you like the changes.

    I have a really bad experience with supporting api level 21 for Eclipse, but I have a feeling you might want to keep on supporting that.

    Thank you for the code! 谢谢.

    opened by Buggaboo 1
  • Merge android studio

    Merge android studio

    The project builds with Android Studio 1.0.*

    The native C/C++ code must be manually compiled with ndk-build. NDK Support has been deprecated by Android Studio.

    opened by Buggaboo 1
  • cant build/run

    cant build/run

    i get the following error using android studio on mac

    Executing tasks: [:app:assembleDebug]

    Configuration on demand is an incubating feature. :app:preBuild :app:compileDebugNdk /Users/bornfree/AndroidstudioProjects/node-android-httpp/app/src/main/jni/async.cpp:31:16: fatal error: uv.h: No such file or directory compilation terminated. make: *** [/Users/bornfree/AndroidstudioProjects/node-android-httpp/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/uvpp-prebuilt//Users/bornfree/AndroidstudioProjects/node-android-httpp/app/src/main/jni/async.o] Error 1

    FAILED

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':app:compileDebugNdk'.

      com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Users/bornfree/ndk-r10b/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/bornfree/AndroidstudioProjects/node-android-httpp/app/build/intermediates/ndk/debug/Android.mk APP_PLATFORM=android-19 NDK_OUT=/Users/bornfree/AndroidstudioProjects/node-android-httpp/app/build/intermediates/ndk/debug/obj NDK_LIBS_OUT=/Users/bornfree/AndroidstudioProjects/node-android-httpp/app/build/intermediates/ndk/debug/lib APP_ABI=all Error Code: 2 Output: /Users/bornfree/AndroidstudioProjects/node-android-httpp/app/src/main/jni/async.cpp:31:16: fatal error: uv.h: No such file or directory compilation terminated. make: *** [/Users/bornfree/AndroidstudioProjects/node-android-httpp/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/uvpp-prebuilt//Users/bornfree/AndroidstudioProjects/node-android-httpp/app/src/main/jni/async.o] Error 1

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    BUILD FAILED

    Total time: 1.803 secs

    opened by pa6lo 1
  • Request: code review of unit tests

    Request: code review of unit tests

    I converted any remaining tests to proper android unit tests.

    I left the libuvpp unit tests alone for now; I'll try to convert those to proper unit tests, once the other tests are working correctly.

    @sequoiar , could you take a look at those tests?

    GPL and MIT are not compatible licences. GPL makes everything it touches GPL, it's viral. I don't know if you realize this.

    opened by Buggaboo 0
  • Merge android studio

    Merge android studio

    The project builds with Android Studio 1.0.*

    The native C/C++ code must be manually compiled with ndk-build. NDK Support has been deprecated by Android Studio.

    opened by Buggaboo 0
Owner
AppNet.Link
Secure P2P Virtual Network Gateway for IoT, Edge and Cloud Applications
AppNet.Link
Run HTTP over UDP with Node.js

nodejs-httpp - Run HTTP over UDP based transport and Bring Web in Peer or P2P styles main js modules: udt.js, httpp.js, udts.js and httpps.js, that's

AppNet.Link 142 Aug 2, 2022
Bearer provides all of the tools to build, run and manage API integrations.

Bearer - The API Integration Framework Bearer provides all of the tools to build, run and manage API Learn more Archive Status Bearer JS has been arch

Bearer.sh 22 Oct 31, 2022
Promise based HTTP client for the browser and node.js

axios Promise based HTTP client for the browser and node.js New axios docs website: click here Table of Contents Features Browser Support Installing E

axios 98k Dec 31, 2022
Ajax for Node.js and browsers (JS HTTP client)

superagent Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features T

Sloth 16.2k Jan 1, 2023
A full-featured http proxy for node.js

node-http-proxy node-http-proxy is an HTTP programmable proxying library that supports websockets. It is suitable for implementing components such as

http ... PARTY! 13.1k Jan 3, 2023
HTTP server mocking and expectations library for Node.js

Nock HTTP server mocking and expectations library for Node.js Nock can be used to test modules that perform HTTP requests in isolation. For instance,

Nock 11.9k Jan 3, 2023
🌐 Human-friendly and powerful HTTP request library for Node.js

Sindre's open source work is supported by the community. Special thanks to: Human-friendly and powerful HTTP request library for Node.js Moving from R

Sindre Sorhus 12.5k Jan 9, 2023
Isomorphic WHATWG Fetch API, for Node & Browserify

isomorphic-fetch Fetch for node and Browserify. Built on top of GitHub's WHATWG Fetch polyfill. Warnings This adds fetch as a global so that its API i

Matt Andrews 6.9k Jan 2, 2023
A light-weight module that brings the Fetch API to Node.js

A light-weight module that brings Fetch API to Node.js. Consider supporting us on our Open Collective: Motivation Features Difference from client-side

Node Fetch 8.1k Jan 4, 2023
SPDY server on Node.js

SPDY Server for node.js With this module you can create HTTP2 / SPDY servers in node.js with natural http module interface and fallback to regular htt

SPDY & HTTP2 in JavaScript 2.8k Jan 4, 2023
libcurl bindings for Node.js

node-libcurl The fastest URL transfer library for Node.js. libcurl bindings for Node.js. libcurl official description: libcurl is a free and easy-to-u

Jonathan Cardoso 565 Jan 2, 2023
Full-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js

rocky A multipurpose, full-featured, middleware-oriented and hackable HTTP/S and WebSocket proxy with powerful built-in features such as versatile rou

Tom 370 Nov 24, 2022
Simplifies node HTTP request making.

Requestify - Simplifies node HTTP request making. Requestify is a super easy to use and extendable HTTP client for nodeJS + it supports cache (-:. Ins

Ran Mizrahi 222 Nov 28, 2022
A fully-featured Node.js REST client built for ease-of-use and resilience

flashheart A fully-featured Node.js REST client built for ease-of-use and resilience flashheart is built on http-transport to provide everything you n

BBC 118 Jun 21, 2022
一个基于node.js,express,socket.io的websocket非常棒的聊天室,代码简单很适合新手. A very nice websocket chat room based on node.js, express, socket.io. the code is simple, very suitable for novices

来来往下看,虽然教程又臭又长但是一步步地保姆式教学很简单的,毕竟我是真菜鸟嘛,当然什么都往细了说╮(╯_╰)╭ 一、使用方法 该教程内容所有指令都为Linux CentOS 7.x环境下指令,其他平台请您自行查询(⊙x⊙;) 1.下载node.js并下载Sakura_Chat_Room node.j

樱樱怪 10 Jul 21, 2022
node

第一步 安装 node node版本须大于14 安装地址http://nodejs.cn/安装页面上的版本即可 下载对应你的系统的安装包 打开安装包,一直下一步到安装完成即可 填入你的cookie inTimeActive 和 longActive 里面的jdCookie.js填入你的cookie

null 6 Feb 17, 2022
QBasic compiler that runs on node.js

QBasic.js QBasic.js allows you to use qb.js inside node projects. Example CLI $ npx qbasic --source=filePath.bas index.js const { compileFile } = requ

Andromeda 3 Oct 24, 2022
Trying to reduce the search time, the objective of this repository is accumulate as many useful code snippets for Node.Js in the real world as possible

Useful Node.Js codes Trying to reduce the search time, the objective of this repository is accumulate as many useful code snippets for Node.Js in the

Juninho 6 Mar 28, 2022
Very very very powerful, extensible http client for both node.js and browser.

ES-Fetch-API 中文 | English Very very very powerful, extensible http client for both node.js and browser. Why should you use ES-Fetch API? Still using a

null 17 Dec 12, 2022