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