在android上向nodejs中添加第三方node模块

版权声明:本文为博主原创文章,如需转载请注明出处,谢谢。 https://blog.csdn.net/zhouxingxingzxy/article/details/45054729

最近,由于学习和工作的需要,调研了一下nodejs在android编译运行的方法以及如何将一个第三方的node模块添加到nodejs中。现在google对nodejs做了官方支持,在这里不做讨论。这篇文章将主要集中在如何解决后面一个问题上。

当我们使用nodej做开发时,有时候难免需要开发一些自己的C++模块,那么这些模块我们该如何添加到node中并可以在android上使用呢?现在先介绍下一些大牛的思路。

由于android对系统的共享库限制的比较严,所以如果是直接交叉编译为android系统可以调用的node模块会很麻烦。所以

The easiest way found so far, has been to compile node-sqlite3 into Node.js as a core module. For this, you just have to copy the node-sqlite3 files into the appropriate places in the Node.js dir and make Node.js aware of the module by adding it to the node.gyp file and adding "NODE_EXT_LIST_ITEM(node_sqlite3)" to the node_extensions.h. Afterwards simply compile the whole thing and the resulting executable should be arm-v5 with node-sqlite3 built-in. Obviously, you will have to remove node-sqlite3 from your node_modules, when deploying your code on a device.

This has been tested with Android-NDK-r8e, Node.js v0.10.18 and node-sqlite3 v2.1.14.





猜你喜欢

转载自blog.csdn.net/zhouxingxingzxy/article/details/45054729