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
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Jan 8, 2023
Java HTTP Request Library

Http Request A simple convenience library for using a HttpURLConnection to make requests and access the response. This library is available under the

Kevin Sawicki 3.3k Jan 6, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Jan 5, 2023
No Internet Layout Library 2.5 0.0 Java #layout #check_internet

No Internet Layout Library Library to check internet connection and change layout to no internet layout if there is no internet. Gradle: allprojects {

Mohamed Wessam 116 Dec 20, 2022
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Dec 24, 2022
:satellite: [Android Library] Simplified async networking in android

Android library that simplifies networking in android via an async http client. Also featured in [Awesome Android Newsletter #Issue 15 ] Built with ❤︎

Nishant Srivastava 36 May 14, 2022
Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

VK.com 104 Dec 12, 2022
Android Easy Http - Simplest android http request library.

Android Easy Http Library 繁體中文文檔 About Android Easy Http Library Made on OkHttp. Easy to do http request, just make request and listen for the respons

null 13 Sep 30, 2022
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Koushik Dutta 6.3k Dec 27, 2022
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

Square 43.4k Jan 5, 2023
A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Square 41k Jan 5, 2023
Android client for ProjectRTC - a WebRTC demo

AndroidRTC WebRTC Live Streaming An Android client for ProjectRTC. It is designed to demonstrate WebRTC video calls between androids and/or desktop br

Chabardes 1.5k Jan 6, 2023
IceNet - Fast, Simple and Easy Networking for Android

IceNet FAST, SIMPLE, EASY This library is an Android networking wrapper consisting of a combination of Volley, OkHttp and Gson. For more information s

Anton Nurdin Tuhadiansyah 61 Jun 24, 2022
Easy, asynchronous, annotation-based SOAP for Android

IceSoap IceSoap provides quick, easy, asynchronous access to SOAP web services from Android devices. It allows for SOAP responses to be bound to Java

Alex Gilleran 75 Nov 29, 2022
dns library for android

Qiniu Happy DNS for Android 安装 直接安装 通过maven 使用方法 DnsManager 可以创建一次,一直使用。 IResolver[] resolvers = new IResolver[3]; resolvers[0] = AndroidDnsSe

Qiniu Cloud 270 Dec 5, 2022
HTTP Server for Android Instrumentation tests

RESTMock REST API mocking made easy. RESTMock is a library working on top of Square's okhttp/MockWebServer. It allows you to specify Hamcrest matchers

Andrzej Chmielewski 750 Dec 29, 2022
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

AMIT SHEKHAR 5.5k Dec 27, 2022
Support for Spring's RestTemplate within native Android applications

Spring for Android Spring for Android is a library that is designed to provide components of the Spring Framework family of projects for use in native

Spring 710 Dec 20, 2022