Nodejs cross-platform compilation (to android) and nodejsandroid

Source: Internet
Author: User

Nodejs cross-platform compilation (to android) and nodejsandroid

Nodejs Binary packages can be installed in two ways: node-gyp and node-pre-gyp.

These two commands are written into the installation script of the package.

Node-gyp is to use the gyp tool to compile the source code, so you must specify the Cross Compiler (see http://n8.io/cross-compiling-nodejs-v0.8)

Node-pre-gyp first considers downloading the binary package from the remote address defined in package. json. If no binary package exists, it is still handed to node-gyp for compilation.

Node-pre-gyp specifies the platform and architecture parameter -- target_platform = "" -- target_arch = "" (see https://www.npmjs.com/package/node-pre-gyp)

Write the script after the above is known.

Example:

# Set cross-compiler 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 ++
# Define the list of libraries to be compiled
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

Make sure that the version of nodejs is consistent. If the file cannot be found during runtime due to inconsistent node versions, manually modify the path. The generation of the tool chain is shown in the last section.

Node Compilation

wget http://nodejs.org/dist/v0.12.4/node-v0.12.4.tar.gztar xvf 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/binmv python2.7 oldpython2.7 && ln -s /usr/bin/python2.7 python2.7cd ../../make
~ /Android-ndk-r9d is the path of ndk
The executable file for the node-v0.12.4/out/Release/node using adb push node/data/local/tmp/node can be executed on the phone

Related Article

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.