Git Product home page Git Product logo

Comments (3)

dna2github avatar dna2github commented on May 29, 2024

@gikarasojo there are several ways to be able to run javascript app.

Method 1:
ref: https://github.com/dna2github/dna2mtgol/blob/master/fileShare

  • Step 1. compile node js with the build script provided in this repo (or download from release page).
  • Step 2. put compiled node js binary file to resource folder of your Android project.
  • Step 3. in MainActivity.java of (ref), InputStream nginx = app.getResources().openRawResource(R.raw.nginx);; you can write code similarly to open a file in application data folder, read the stream and write to the file; grant executing permission to the file
  • Step 4. similar to NginxServer.java of (ref), p = Runtime.getRuntime().exec(cmd); you can write some code to start a thread and set cmd for example /data/data/com.myapp.nodejs/binary_nodejs /sdcard/hello/index.js (i.e. class Server extends Thread { @override public void run() { String cmd = "/data/data/com.myapp.nodejs/binary_nodejs /sdcard/hello/index.js"; Process p = Runtime.getRuntime().exec(cmd); p.waitFor(); /* new Server().start() to kick off the background server and kill p when want to stop*/ } }, the difference between Nginx and NodeJS is that Nginx runs in daemon mode and NodeJS runs in foreground, if you directly run in the code without a thread, waitFor method will block your app until the NodeJS process is terminated.). Then p is a process of node js app. (if you run a js server, remember to declare permission statement in AndroidManifest.xml)

Method 2:
ref: https://github.com/shadowsocks/shadowsocks-android

  • Step 1. read the configuration of src/main/jni/Android.mk in (ref); copy the build script provided in this repo into the file with Makefile style; config resource folder as build target
  • Step 2-3. the same to Step 3-4 of Method 1

Method 3:

If you know some Linux system programming, you can also use mmap, load node js binary into memory and then run node js app, to save storage space.

Method ...

Thanks,
Seven

from dna2oslab.

dna2github avatar dna2github commented on May 29, 2024

update: https://github.com/dna2github/dna2mtgol/tree/master/nodeBase/platform
a simple android app to run NodeJS

from dna2oslab.

dna2github avatar dna2github commented on May 29, 2024

there is README file to have a guide. close it.

from dna2oslab.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.