nodejs 在 android 系统里面怎么运行啊
发布于 2年前 作者 jemen168 2761 次浏览

nodejs 在 android 系统里面怎么运行

5 回复

不支持的吧,等官方移植吧,不过好像意义不太大

意义挺大的,低功耗低开发成本的服务器

帮楼主搜索了一下。

http://d.hatena.ne.jp/forest1040/20110318/1300460817

小日本的解决方案,英文版,打不开记得翻墙。

还有group上有人提到的,我给你复制下来吧。翻译太烂 自己看吧。

Some issues you may run into if you try this:

  • Android applications only deal with native code in shared libraries. You’ll want to repackage node.js as a shared library.

  • Combining event loops. Android uses an epoll event loop to handle events, and so does node.js. You will have to figure out how to combine these two event loops together.

  • Node.js has its own custom make system, and so does Android, and they aren’t the same. You’ll have to figure out how to work around this.

  • Javascript to Java bridge. Many Android APIs can only be accessed from Java. You’ll want to write a V8 to JNI bridge. (JNI is the standard way for C/C++ code to call Android Java code.)

  • Some Android APIs require subclassing Java classes. You can deal with this by subclassing the Java APIs with Java classes that forward to Javascript.

  • Node wants to run on the main thread, but some Android APIs will throw runtime exceptions if you call them from the main thread. (They do this because they block.) You’ll have to figure out a way around this, perhaps by having helper Java classes that run on secondary threads.

我觉得把它当做一个app那样去运行很困难,那样要做的太多了。正如你上面所找到的,那些api神马的,修改的工作量的不亚于从头再来

还有一个可行的方向是运行在android底层的linux上,直接交叉编译进去,再另行制作app与之交互。不过这样的话,就只能运行在root过的机器上了,也是个不小的缺点

从 NodeJS官网上下的Linux版本在ubuntu系统上 是可以运行的,在android就跑不起来了

回到顶部