Building and running Node.js for Android
转自: http://www.goland.org/nodejsonandroid/
Building and running Node.js for Android
October 14, 2014 / By Administrator / In Thali / 19 Comments
1 Building Node.js for Android
- Go find a Linux machine or maybe a Mac.
- These instructions don’t currently work on Windows due to issues with the sh scripts being used. Yes, I did try the scripts in MINGW32 and no it didn’t work.
- Go download the Android NDK.
- Which NDK to download does take a bit of attention. Most Android devices today are 32 bit so I want the Platform (32-bit target). But my Linux OS (Elementary OS) is 64 bit so I want Linux 64-bit (x86) under Platform (32-bit target).
- After downloading the NDK unzip it.
- Let’s assume you put the NDK into ~/android-ndk-r10b.
- Go clone node.
- Let’s assume you put that into ~/node. I am running these instructions off master branch.
- Check that you have all of node’s dependencies as listed here
- I believe any modern Linux distro will have all of these already but just in case I decided to include the link.
- Go edit ~/node/android-configure and change ’arm-linux-androideabi-4.7’ to instead be ’arm-linux-androideabi-4.8.
- This is the pull request that added basic Android support to Node. It contains some instructions. The first instruction will set up the build environment for Android. But the set up script is designed for an older version of the Android NDK. So we need to update it. Specifically 4.7 is apparently not supported by NDK 10 so I switched it to 4.8 which is. I decided to leave platform=android-9 for no particularly good reason.
- Run from inside of ~/node directory the command “source ./android-configure ~/android-ndk-r10b”
- Now go to ~/node/android-toolchain/bin and issue the command “mv python2.7 oldpython2.7 && ln -s /usr/bin/python2.7 python2.7”
- The NDK appears to ship with its own version of Python 2.7 that doesn’t support a library (bz2) that is needed by files in the NDK. In any sane world this just means that the NDK is broken but I’m sure there is some logic here. This bug was reported to Node (since it breaks Node’s support of Android) but they responded that this is an NDK issue so Google should deal with it. But if we want to build we have to get connected to a version of Python that does support bz2. That’s what we did above. We linked the main version of Python (which any sane Linux distro will use) with the NDK so it will use that and hence support bz2.
- Now go to ~/node and issue ’make’
- The actual instructions from the checkin say to run ’make -j8’ which enables parallel capabilities in Make. Apparently the rule of thumb is to set the value after j to 2x the number of hardware threads available on the machine.
- On my Linux VM the build takes forever so now is a good time to get some fresh tea.
2 Using Node.js on Android via ADB
- Issue the command “adb push ~/node/out/Release /data/local/tmp/Release”
- There is a step I’m skipping here. I actually do my development on Windows. So I copy the Release folder from my Linux VM (via Virtualbox) and then use the linked drive to move it to my Windows box. So in fact my adb push command above isn’t from the Linux location but my Windows location.
- The out/Release folder contains all the build artifacts for Node. Of this mess I suspect only the node executable is actually needed. But for the moment I’m going to play it safe and just move everything over.
- The reason for putting the node materials into /data/local/tmp/Release is because /data/local/tmp is one of the few areas where we can execute the chmod command in the next step and make Node executable. But when we wrap this thing up in an AAR we can actually use the setExecutable function instead.
- Issue “adb shell”. Once in the shell issue “chmod 700 /data/local/tmp/Release/node”
- I then issued an ’adb push’ for a simple hello world node program I have that I put inside of /data/local/tmp
- I used “Hello HTTP” from http://howtonode.org/hello-node
- Then I went in via “adb shell” and ran “/data/local/tmp/Release/node helloworld.js”
- And yes, it worked! I even tested it by going to the browser on the phone and navigating to http://localhost:8000.
- To kill things I just ctrl-c which does kill the adb shell but also the node app. Good enough for now.
3 What about NPM?
19 Responses to Building and running Node.js for Android
Pingback: Making HTML 6 Packaged Apps Happen | Stuff Yaron Finds Interesting
Pingback: Looking at JXCore’s perf |
-
- Administrator
If Bing Translate is handling things correctly then you want to use node.js with an Android tablet. The instructions I posted should work just fine with an Android tablet. But at this point I would take a look at JXCore. They run node just fine on Android and are more mature than the instructions I provided.
- Ismael Olea
Great great post.
FYI: I’ve realised this method doesn’t work in Android 5.* due a broken ABI, so I had to research how to solve it. I finally got it running. This is written here: http://olea.org/diario/archive/2015/Abr.-11-1.html
Thanks!
- Administrator
Yup, I wrote these instructions using KitKat so I’m not surprised that the PIE fun broke things on 5.0. Thanks for documenting the fix. Right now we are mostly focusing on just using JXCore and letting them figure it all out for us. :)
- Ismael Olea
BTW, any experience on populating npm dependencies for running node.js apps in Android? I’m getting a little bit mad with this.
- Administrator
It depends on the dependencies. If you are using pure Javascript dependencies (which as I’ve previously explored is most of them) then you can just run NPM on the parent OS and copy the node_module sub-directory into /data/local/tmp. If you are running node.js from there then it should just work (for non-native add-ons).
But seriously, give JXCore a try. They have solved a bunch of these issues and are completely open source.
Has there been a solution for Building and running Node.js for Android using Windows?
1. Go find a Linux machine or maybe a Mac.
These instructions don’t currently work on Windows due to issues with
the sh scripts being used. Yes, I did try the scripts in MINGW32 and no
it didn’t work.
AdministratorI have to admit that since discovering JXCore I haven’t really followed up on this approach. I’d rather they deal with it. :)
Ritesh KumarHi
I am trying to create and run node.js app in android and following the
steps as discussed by you in this post but i am facing the issue
“Node.js configure error: No acceptable C compiler found!
Please make sure you have a C compiler installed on your system and/or
consider adjusting the CC environment variable if you installed
it in a non-standard prefix.”
when i am trying to run this command “source ./android-configure ~/android-ndk-r10b”.
I installed all the required software :-
* GCC 4.2 or newer
* G++ 4.2 or newer
* Python 2.6 or 2.7
* GNU Make 3.81 or newer
* libexecinfo (FreeBSD and OpenBSD only)Please let me know what can be the issue for this.Thanks in advance.
AdministratorI vaguely remember running into this as
well. I think node.js wanted a very specific version of C. What OS are
running on? You listed libexecinfo so are you on FreeBSD or OpenBSD?
Have you succeeded initializing the
JXcore engine in 1 thread but then calling a JS funciton from another?
I’m having difficulties accomplish this and they are not answering…
AdministratorI looked for your issue, I’m guessing your github ID is oriharel? I didn’t see anything from that user filed at https://github.com/jxcore/jxcore/issues. Where did you ask the JXCore folks this question?
CristianHi! I’m wondering if it’s any chance to have this native library compiled in Android for node:
https://github.com/voodootikigod/node-serialport
AdministratorI never could figure out how to get
node-gyp to compile to Android. I eventually gave up when we moved
completely to JXCore. If node-serialport will compile with JXCore on the
desktop (make sure that pre-build is off or you will get the wrong
binary) then you have some hope of getting it to work with JXCore on
Android. No guarantees, it depends on if the C libraries it is using are
supported on Android.
Building and running Node.js for Android的更多相关文章
- [Server Running] [Node.js, PM2] Using PM2 To Keep Your Node Apps Alive
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allow ...
- 转 node.js和 android中java加密解密一致性问题;
原文地址,请大家去原文博客了解; http://blog.csdn.net/linminqin/article/details/19972751 我保留一份,防止删除: var crypto = re ...
- [转]Node.js tutorial in Visual Studio Code
本文转自:https://code.visualstudio.com/docs/nodejs/nodejs-tutorial Node.js tutorial in Visual Studio Cod ...
- 在Window IIS中安装运行node.js应用—你疯了吗
[原文发表地址]Installing and Running node.js applications within IIS on Windows - Are you mad? [原文发表时间]201 ...
- 一个完整的Node.js RESTful API
前言 这篇文章算是对Building APIs with Node.js这本书的一个总结.用Node.js写接口对我来说是很有用的,比如在项目初始阶段,可以快速的模拟网络请求.正因为它用js写的,跟i ...
- how to updating Node.js and npm
how to updating Node.js and npm 1 Installing Node.js and updating npm How do I update Node.js ? Not ...
- [转]Building a REST-Backend for Angular with Node.js & Express
本文转自:https://malcoded.com/posts/angular-backend-express Angular is a single page application framewo ...
- [译]Node.js : Building RESTful APIs using Loopback and MySQL
国庆后可能就要使用StrongLoop那套东西来做项目了 原文:http://www.javabeat.net/loopback-mysql/ Loopback是什么? Loopback是一个开源的N ...
- Practical Node.js (2018版) 第8章:Building Node.js REST API Servers
Building Node.js REST API Servers with Express.js and Hapi Modern-day web developers use an architec ...
随机推荐
- 《C++反汇编与逆向分析技术揭秘》之11——虚函数
虚函数的机制 当类中定义有虚函数时,编译器会将该类中所有虚函数的首地址保存在一张地址表中,这张表被称为虚函数地址表.编译器还会在类中添加一个虚表指针. 举例: CVirtual类的构造函数中没有进行任 ...
- TYVJ P1933 绿豆蛙的归宿 题解(未完成)
P1933 「Poetize3」绿豆蛙的归宿 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找 ...
- Linux C 网络编程 - 获取本地 ip 地址,mac,通过域名获取对应的 ip
获取本地 ip 地址,mac,通过域名获取对应的 ip, 是网络编程可能遇到的比较常见的操作了,所以总结如下(封装了3个函数), 直接上代码: #include <stdio.h> #in ...
- 微软URLRewriter.dll的url重写的简单使用(实现伪静态)
先添加引用URLRewriter.dll到项目下的bin目录中,下载: http://files.cnblogs.com/tianguook/URLRewriter.rar 1.在web.config ...
- Fragment 生命周期 事务 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 【SSH三大框架】Hibernate基础第十一篇:对继承映射的操作
在java中.类之间能够有继承关系.可是在数据库中是没有继承关系的.只是Hibernate是为了把面向对象的关系反映到数据库中.Hibernate为我们提供了3种方案: 第一.一个继承体系放在一张表中 ...
- [Algorithm] Dynamic programming: Find Sets Of Numbers That Add Up To 16
For a given array, we try to find set of pair which sums up as the given target number. For example, ...
- PHP快速入门 如何配置Apache服务器
点击安装Apache,一直下一步 填写域名(Network Domain),服务器名(Server Name),和管理员邮箱(三条都可以任意填写) 下一步的时候选择(Custom),然后在Apache ...
- es5 - array - reverse
/** * 描述:也就是数组元素反转 * 使用:arr.reverse() */ var a = [1,2,3]; console.log(a.reverse()); /** * 一个经典的问题:如何 ...
- tomcat启动报错,找不到相应的 queue,从而引发内存泄漏
tomcat启动报错,无法创建 bean listenerStatusChangeDealHandler, no queue 'STOCK.NOTIFY_CHANGE.INTER.CACHE.QUEU ...