简体   繁体   English

在 Android 上运行 Node.Js

[英]Running Node.Js on Android

So I know this has been questioned quite a lot.所以我知道这已经受到了很多质疑。 To be exact for example in these questions:准确地说,例如在这些问题中:

  1. Run NodeJs server in Android 在 Android 中运行 NodeJs 服务器
  2. How to run my node.js project on android? 如何在 android 上运行我的 node.js 项目?
    and
  3. NodeJS on IOS/Android IOS/Android 上的 NodeJS

Every option presented has a problem though:提出的每个选项都有一个问题:

  • I want to run it on my normal device so I would like to avoid installing another OS on my Device我想在我的普通设备上运行它,所以我想避免在我的设备上安装另一个操作系统

  • Work on JXCore was stopped last month and (maybe as a result) I couldn't get it to compile (see Can't install jxcore-cordova )上个月 JXCore 的工作停止了,(可能因此)我无法编译它(请参阅无法安装 jxcore-cordova

  • The Android Port of NodeJs Anode has not been worked on since 2014 and wasn't really maintained back then anyways NodeJs Anode的 Android 端口自 2014 年以来一直没有开发过,而且当时也没有真正维护过
  • The second answer in the second thread I linked to mentioned there is an official node distribution for Android now but apart from a link to the Browse-Website of the latest dist I couldn't find any info on how to actually use it我链接到的第二个线程中的第二个答案提到现在有一​​个官方的 Android 节点发行版,但除了指向最新发行版的浏览网站的链接之外,我找不到有关如何实际使用它的任何信息
  • I also saw this but it seems like the device has to be connected to a PC (or similar) to run the adb shell commands while I would like to make it as a separate App我也看到了这一点,但似乎设备必须连接到 PC(或类似设备)才能运行 adb shell 命令,而我想将其作为单独的应用程序

With the time that past since these questions have been posted and as the "best option" JXCore seem to be now unusable:自从这些问题发布以来,随着时间的推移,作为“最佳选择”,JXCore 现在似乎无法使用:
Is there a way to run a node.js application (a server in my case) on an Android device?有没有办法在 Android 设备上运行 node.js 应用程序(在我的例子中是服务器)?

if you're wondering why I'd want this: I made a WebApp with a Node.Js server and I now want a version you can launch locally from your phone without requiring an Internet connection.如果你想知道为什么我想要这个:我用 Node.Js 服务器制作了一个 WebApp,我现在想要一个版本,你可以从手机本地启动,而无需互联网连接。 This means the server needs to run on an Android phone.这意味着服务器需要在 Android 手机上运行。

I just had a jaw-drop moment - Termux allows you to install NodeJS on an Android device!我刚刚有一个令人惊叹的时刻 - Termux允许您在 Android 设备上安装NodeJS

It seems to work for a basic Websocket Speed Test I had on hand.它似乎适用于我手头的基本Websocket 速度测试 The http served by it can be accessed both locally and on the network.它提供的 http 可以在本地和网络上访问。

There is a medium post that explains the installation process有一个中等帖子解释了安装过程

Basically: 1. Install termux 2. apt install nodejs 3. node it up!基本上: 1. 安装 termux 2. apt install nodejs 3. node it up!

One restriction I've run into - it seems the shared folders don't have the necessary permissions to install modules.我遇到的一个限制 - 共享文件夹似乎没有安装模块的必要权限。 It might just be a file permission thing.它可能只是一个文件权限问题。 The private app storage works just fine.私人应用程序存储工作得很好。

Dory - node.js 多莉 - node.js

Great New Application很棒的新应用
No Need to root your Phone and You Can Run your js File From anywere.无需root你的手机,你可以从任何地方运行你的js文件。

  • node.js runtime(run ES2015/ES6, ES2016 javascript and node.js APIs in android) node.js 运行时(在 android 中运行 ES2015/ES6、ES2016 javascript 和 node.js API)
  • API Documents and instant code run from doc API 文档和即时代码从 doc 运行
  • syntax highlighting code editor语法高亮代码编辑器
  • npm supports npm 支持
  • linux terminal(toybox 0.7.4). linux 终端(玩具盒 0.7.4)。 node.js REPL and npm command in shell (add '--no-bin-links' option if you execute npm in /sdcard) shell 中的 node.js REPL 和 npm 命令(如果在 /sdcard 中执行 npm,则添加“--no-bin-links”选项)
  • StartOnBoot / LiveReload StartOnBoot / LiveReload
  • native node.js binary and npm are included.包括原生 node.js 二进制文件和 npm。 no need to be online.无需在线。

Update instruction to node js 8 (async await)更新节点 js 8 的指令(异步等待)

  1. Download node.js v8.3.0 arm zip file and unzip.下载 node.js v8.3.0 arm zip 文件并解压。

  2. copy 'node' to android's sdcard(/sdcard or /sdcard/path/to/...)将“节点”复制到 android 的 sdcard(/sdcard 或 /sdcard/path/to/...)

  3. open the shell(check it out in the app's menu)打开外壳(在应用程序的菜单中查看)

  4. cd /data/user/0/io.tmpage.dorynode/files/bin (or, just type cd && cd .. && cd files/bin ) cd /data/user/0/io.tmpage.dorynode/files/bin (或者,只需输入 cd && cd .. && cd files/bin )

  5. rm node节点

  6. cp /sdcard/node . cp /sdcard/节点。

  7. (chmod a+x node (chmod a+x 节点

( https://play.google.com/store/apps/details?id=io.tempage.dorynode&hl=en ) https://play.google.com/store/apps/details?id=io.tempage.dorynode&hl=en

You can use Node.js for Mobile Apps .您可以将Node.js 用于移动应用程序

It works on Android devices and simulators, with pre-built binaries for armeabi-v7a, x86, arm64-v8a, x86_64.它适用于 Android 设备和模拟器,具有适用于 armeabi-v7a、x86、arm64-v8a、x86_64 的预构建二进制文件。 It also works on iOS, though that's outside the scope of this question.它也适用于 iOS,尽管这超出了本问题的范围。

Like JXcore, it is used to host a Node.js engine in the same process as the app, in a dedicated thread.与 JXcore 一样,它用于在与应用程序相同的进程中,在专用线程中托管 Node.js 引擎。 Unlike JXcore, it is basically pure Node.js, built as a library, with a few portability fixes to run on Android.与 JXcore 不同,它基本上是纯 Node.js,构建为一个库,并带有一些可移植性修复以在 Android 上运行。 This means that it's much easier to keep the project up to date with mainline Node.js.这意味着使用主线 Node.js 使项目保持最新状态要容易得多。

Plugins for Cordova and React Native are also available. CordovaReact Native 的插件也可用。 The plugins provide a communication layer between the JavaScript side of those frameworks and the Node.js side.这些插件在这些框架的 JavaScript 端和 Node.js 端之间提供了一个通信层。 They also simplify development by taking care of a few things automatically, like packaging modules and cross-compiling native modules at build time.它们还通过自动处理一些事情来简化开发,比如在构建时打包模块和交叉编译本机模块。

Full disclosure: I work for the company that develops Node.js for Mobile Apps.完全披露:我在为移动应用程序开发 Node.js 的公司工作。

J2V8 is best solution of your problem. J2V8 是您问题的最佳解决方案。 It's run Nodejs application on jvm(java and android).它在 jvm(java 和 android)上运行 Nodejs 应用程序。

J2V8 is Java Bindings for V8, But Node.js integration is available in J2V8 (version 4.4.0) J2V8 是 V8 的 Java 绑定,但 Node.js 集成在 J2V8(版本 4.4.0)中可用

Github : https://github.com/eclipsesource/J2V8 Github: https : //github.com/eclipsesource/J2V8

Example : http://eclipsesource.com/blogs/2016/07/20/running-node-js-on-the-jvm/示例: http : //eclipsesource.com/blogs/2016/07/20/running-node-js-on-the-jvm/

the tutorial of how to build NodeJS for Android https://github.com/dna2github/dna2oslab/tree/master/android/build安卓NodeJS搭建教程https://github.com/dna2github/dna2oslab/tree/master/android/build
there are several versions v0.12, v4, v6, v7有几个版本 v0.12、v4、v6、v7

It is easy to run compiled binary on Android;在 Android 上运行编译后的二进制文件很容易; for example run compiled Nginx: https://github.com/dna2github/dna2mtgol/tree/master/fileShare例如运行编译的 Nginx: https : //github.com/dna2github/dna2mtgol/tree/master/fileShare

You just need to modify code to replace Nginx to NodeJS;您只需要修改代码即可将Nginx替换为NodeJS; it is better if using Android Service to run node js server on the backend.如果使用 Android Service 在后端运行 node js 服务器会更好。

Node.js Frontend for Android适用于 Android 的 Node.js 前端

  • releases include signed apks 发布包括签名的apk
  • Android 4.4+安卓 4.4+
  • open source (GPLv2)开源 (GPLv2)
  • no root无根
  • frontend for Node.js for Mobile Apps by Janea Systems Janea Systems 的移动应用程序 Node.js前端
    • which was announced earlier in this thread by one of its developers这是由其开发人员之一在此线程中早些时候宣布的
    • which is a game-changer;这是一个游戏规则改变者; great work!很棒的工作!
  • at a high level:在高层次上:
    • the "exec in same process" tab: “在同一进程中执行”选项卡:
      • includes a list of Node.js apps that are intended to run for a short period of time while the application remains open, and may only be executed one at a time包括一系列 Node.js 应用程序,这些应用程序旨在在应用程序保持打开状态时运行一小段时间,并且一次只能执行一个
    • the "fork to separate process" tab: “分叉到分离进程”选项卡:
      • includes a list of Node.js apps that are each executed in a separate foreground service in a distinct process, and are intended to hold long-running daemons (ex: various types of servers)包括 Node.js 应用程序列表,每个应用程序都在不同进程中的单独前台服务中执行,旨在容纳长时间运行的守护进程(例如:各种类型的服务器)

截图动画

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM