Nodejs Cross (cross-platform) compilation (to Android)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.