Nodejs binary packages are available in two mounting modes Node-gyp and NODE-PRE-GYP
These two commands are written to the installation script for the package.
NODE-GYP is compiling the source code using the Gyp tool, so you must specify a cross-compiler (see http://n8.io/cross-compiling-nodejs-v0.8/)
NODE-PRE-GYP first consider downloading the binary package from the remote address defined by the Package.json, and if none, it will still be given to NODE-GYP compilation
Node-pre-gyp the parameters for the specified platform and schema are--target_platform= ""--target_arch= "(see HTTPS://WWW.NPMJS.COM/PACKAGE/NODE-PRE-GYP)
The script is written after the above known.
Example:
#设置交叉编译器export AR=~/node-v0.12.4/android-toolchain/arm-linux-androideabi/bin/arExport CC=~/node-v0.12.4/android-toolchain/arm-linux-androideabi/bin/GCC
Export CXX=~/node-v0.12.4/android-toolchain/arm-linux-androideabi/bin/g++
export LINK=~/node-v0.12.4/android-toolchain/arm-linux-androideabi/bin/g++
#定义需要编译的库列表
m=(Hiredis iconv sqlite3)
for i in ${m[*]};
Do
CD node_modules/$i
CNPM Run-script install --target_platform="android" --target_ Arch="arm"
CD.. /.. /
Done
Note that the version of Nodejs is consistent, and if the runtime cannot find the file because of node version inconsistency, modify the path manually. Tool chain Generation look at the last paragraph.
Finally, node is compiled.
wgethttp//nodejs.org/dist/v0.12.4/node-v0.12.4.tar.gzTarXVF Node-v0.12.4.Tar. GZCD node-v0.12.4sed-I."s/arm-linux-androideabi-4.7/arm-linux-androideabi-4.8/g"android-Configuresource./android-configure ~/android-ndk-R9DCD Android-toolchain/binMVPython2.7Oldpython2.7&&LN-s/usr/bin/python2.7Python2.7CD../.. / Make
~/android-ndk-r9d is the path of the NDK
Executable file for Node-v0.12.4/out/release/node using ADB push node/data/local/tmp/node can be executed on the phone
Nodejs Cross (cross-platform) compilation (to Android)