(OK) 交叉编译node-v4.2.1—for—android
参考:http://www.goland.org/nodejsonandroid/
第1步:下载node-v4.2.1
[root@localhost node-v4.2.1]# wget -c https://nodejs.org/download/release/latest/node-v4.2.1-linux-armv7l.tar.gz
[root@localhost node-v4.2.1]# pwd
/opt/cBPM-android/node-v4.2.1
第2步:查看、编辑 android-configure文件内容
[root@localhost node-v4.2.1]# gedit android-configure
------------------------------------------------------------------------------下面是android-configure文件内容
#!/bin/bash
export TOOLCHAIN=$PWD/android-toolchain
mkdir -p $TOOLCHAIN
$1/build/tools/make-standalone-toolchain.sh \
--toolchain=arm-linux-androideabi-4.9 \
--arch=arm \
--install-dir=$TOOLCHAIN \
--platform=android-14
export PATH=$TOOLCHAIN/bin:$PATH
export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
export CC=$TOOLCHAIN/bin/arm-linux-androideabi-gcc
export CXX=$TOOLCHAIN/bin/arm-linux-androideabi-g++
export LINK=$TOOLCHAIN/bin/arm-linux-androideabi-g++
./configure \
--dest-cpu=arm \
--dest-os=android
------------------------------------------------------------------------------
第3步:Run from inside of node directory the command
[root@localhost node-v4.2.1]# . android-configure /opt/android-on-linux/android-ndk-r10d
第4步:mv python2.7 oldpython2.7 && ln -s /usr/bin/python2.7 python2.7
[root@localhost node-v4.2.1]# cd android-toolchain/bin/
[root@localhost bin]# pwd
/opt/cBPM-android/node-v4.2.1/android-toolchain/bin
[root@localhost bin]# ls
arm-linux-androideabi-addr2line arm-linux-androideabi-gcc arm-linux-androideabi-ld arm-linux-androideabi-size
arm-linux-androideabi-ar arm-linux-androideabi-gcc-4.9 arm-linux-androideabi-ld.bfd arm-linux-androideabi-strings
arm-linux-androideabi-as arm-linux-androideabi-gcc-ar arm-linux-androideabi-ld.gold arm-linux-androideabi-strip
arm-linux-androideabi-c++ arm-linux-androideabi-gcc-nm arm-linux-androideabi-ld.mcld python
arm-linux-androideabi-c++filt arm-linux-androideabi-gcc-ranlib arm-linux-androideabi-nm python2
arm-linux-androideabi-cpp arm-linux-androideabi-gcov arm-linux-androideabi-objcopy python2.7
arm-linux-androideabi-dwp arm-linux-androideabi-gcov-tool arm-linux-androideabi-objdump
arm-linux-androideabi-elfedit arm-linux-androideabi-gdb arm-linux-androideabi-ranlib
arm-linux-androideabi-g++ arm-linux-androideabi-gprof arm-linux-androideabi-readelf
[root@localhost bin]# mv python2.7 oldpython2.7
[root@localhost bin]# ln -s /usr/bin/python2.7 python2.7
[root@localhost bin]#
[root@localhost node-v4.2.1]# cd android-toolchain/bin/; mv python2.7 oldpython2.7; ln -s /usr/bin/python2.7 python2.7; cd -
第5步:编译node
[root@localhost node-v4.2.1]# make -j5
注意:编译时,如果遇到大量的 类型 定义 冲突错误,很可能是版本的问题:android-ndk-(r8e, r9d, r10d)、platforms/android-(14, 19, 21, ...)
-----------------------------------------------------------------编译时,出现问题如下
error: undefined reference to 'getpwuid_r'
解决方法(使用getpwuid替换getpwuid_r):
[root@localhost node-v4.2.1]# grep getpwuid_r -R .
[root@localhost node-v4.2.1]# gedit ./deps/uv/src/unix/core.c
将
//r = getpwuid_r(uid, &pw, buf, bufsize, &result);
替换为:
//r = getpwuid_r(uid, &pw, buf, bufsize, &result);
result = getpwuid(uid);
if(result == NULL) r = 0;
-----------------------------------------------------------------至此,编译成功,下面测试
//宿主机
[root@localhost ~]# adb root
[root@localhost ~]# adb shell
//手机
root@mb526:/ # mkdir -p /data/data/node/Release
root@mb526:/ #
//宿主机
[root@localhost node-v4.2.1]# pwd
/opt/cBPM-android/node-v4.2.1
[root@localhost node-v4.2.1]# du -hs out/Release/
100M out/Release/
[root@localhost node-v4.2.1]# adb push out/Release/ /data/data/node/Release //将node复制到手机
//手机
root@mb526:/ # cd /data/data/node/Release
root@mb526:/ # chmod 700 node
//宿主机
[root@localhost node-v4.2.1]# gedit out/Release/helloworld.js //内容如下(红色):
//-------------------------------------
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
//-------------------------------------(更多例子:http://howtonode.org/hello-node)
//宿主机
[root@localhost node-v4.2.1]# adb push out/Release/helloworld.js /data/data/node/Release
//手机
root@mb526:/data/data/node/Release # ./node helloworld.js
//宿主机,浏览器,成功访问
http://192.168.0.101:8000/
至此,OK
-----------------------------------------------------------------编译时,可能出现问题 如下
在安装node.js时提示ImportError: No module named bz2。
这个python中没有装bz2的库导致的。
解决方法:
yum install bzip2-devel
---------------------------
error: undefined reference to 'getpwuid_r'
出现这个错误是因为我使用了 --platform=android-14 , 修改为 --platform=android-21
Answer 1:The API level in our build script was recently raised to 21, closing. If you need support for an API level < 21, a patch would be welcome
Answer 2:There is no getpwuid_r implementation in bionic libc in Android platforms below 19. Just remove the call off the code.
---------------------------
-----------------------------------------------------------------
第1步:下载node-v4.2.1
[root@localhost node-v4.2.1]# wget -c https://nodejs.org/download/release/latest/node-v4.2.1-linux-armv7l.tar.gz
[root@localhost node-v4.2.1]# pwd
/opt/cBPM-android/node-v4.2.1
第2步:查看、编辑 android-configure文件内容
[root@localhost node-v4.2.1]# gedit android-configure
------------------------------------------------------------------------------下面是android-configure文件内容
#!/bin/bash
export TOOLCHAIN=$PWD/android-toolchain
mkdir -p $TOOLCHAIN
$1/build/tools/make-standalone-toolchain.sh \
--toolchain=arm-linux-androideabi-4.9 \
--arch=arm \
--install-dir=$TOOLCHAIN \
--platform=android-14
export PATH=$TOOLCHAIN/bin:$PATH
export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
export CC=$TOOLCHAIN/bin/arm-linux-androideabi-gcc
export CXX=$TOOLCHAIN/bin/arm-linux-androideabi-g++
export LINK=$TOOLCHAIN/bin/arm-linux-androideabi-g++
./configure \
--dest-cpu=arm \
--dest-os=android
------------------------------------------------------------------------------
第3步:Run from inside of node directory the command
[root@localhost node-v4.2.1]# . android-configure /opt/android-on-linux/android-ndk-r10d
第4步:mv python2.7 oldpython2.7 && ln -s /usr/bin/python2.7 python2.7
[root@localhost node-v4.2.1]# cd android-toolchain/bin/
[root@localhost bin]# pwd
/opt/cBPM-android/node-v4.2.1/android-toolchain/bin
[root@localhost bin]# ls
arm-linux-androideabi-addr2line arm-linux-androideabi-gcc arm-linux-androideabi-ld arm-linux-androideabi-size
arm-linux-androideabi-ar arm-linux-androideabi-gcc-4.9 arm-linux-androideabi-ld.bfd arm-linux-androideabi-strings
arm-linux-androideabi-as arm-linux-androideabi-gcc-ar arm-linux-androideabi-ld.gold arm-linux-androideabi-strip
arm-linux-androideabi-c++ arm-linux-androideabi-gcc-nm arm-linux-androideabi-ld.mcld python
arm-linux-androideabi-c++filt arm-linux-androideabi-gcc-ranlib arm-linux-androideabi-nm python2
arm-linux-androideabi-cpp arm-linux-androideabi-gcov arm-linux-androideabi-objcopy python2.7
arm-linux-androideabi-dwp arm-linux-androideabi-gcov-tool arm-linux-androideabi-objdump
arm-linux-androideabi-elfedit arm-linux-androideabi-gdb arm-linux-androideabi-ranlib
arm-linux-androideabi-g++ arm-linux-androideabi-gprof arm-linux-androideabi-readelf
[root@localhost bin]# mv python2.7 oldpython2.7
[root@localhost bin]# ln -s /usr/bin/python2.7 python2.7
[root@localhost bin]#
[root@localhost node-v4.2.1]# cd android-toolchain/bin/; mv python2.7 oldpython2.7; ln -s /usr/bin/python2.7 python2.7; cd -
第5步:编译node
[root@localhost node-v4.2.1]# make -j5
注意:编译时,如果遇到大量的 类型 定义 冲突错误,很可能是版本的问题:android-ndk-(r8e, r9d, r10d)、platforms/android-(14, 19, 21, ...)
-----------------------------------------------------------------编译时,出现问题如下
error: undefined reference to 'getpwuid_r'
解决方法(使用getpwuid替换getpwuid_r):
[root@localhost node-v4.2.1]# grep getpwuid_r -R .
[root@localhost node-v4.2.1]# gedit ./deps/uv/src/unix/core.c
将
//r = getpwuid_r(uid, &pw, buf, bufsize, &result);
替换为:
//r = getpwuid_r(uid, &pw, buf, bufsize, &result);
result = getpwuid(uid);
if(result == NULL) r = 0;
-----------------------------------------------------------------至此,编译成功,下面测试
//宿主机
[root@localhost ~]# adb root
[root@localhost ~]# adb shell
//手机
root@mb526:/ # mkdir -p /data/data/node/Release
root@mb526:/ #
//宿主机
[root@localhost node-v4.2.1]# pwd
/opt/cBPM-android/node-v4.2.1
[root@localhost node-v4.2.1]# du -hs out/Release/
100M out/Release/
[root@localhost node-v4.2.1]# adb push out/Release/ /data/data/node/Release //将node复制到手机
//手机
root@mb526:/ # cd /data/data/node/Release
root@mb526:/ # chmod 700 node
//宿主机
[root@localhost node-v4.2.1]# gedit out/Release/helloworld.js //内容如下(红色):
//-------------------------------------
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
//-------------------------------------(更多例子:http://howtonode.org/hello-node)
//宿主机
[root@localhost node-v4.2.1]# adb push out/Release/helloworld.js /data/data/node/Release
//手机
root@mb526:/data/data/node/Release # ./node helloworld.js
//宿主机,浏览器,成功访问
http://192.168.0.101:8000/
至此,OK
-----------------------------------------------------------------编译时,可能出现问题 如下
在安装node.js时提示ImportError: No module named bz2。
这个python中没有装bz2的库导致的。
解决方法:
yum install bzip2-devel
---------------------------
error: undefined reference to 'getpwuid_r'
出现这个错误是因为我使用了 --platform=android-14 , 修改为 --platform=android-21
Answer 1:The API level in our build script was recently raised to 21, closing. If you need support for an API level < 21, a patch would be welcome
Answer 2:There is no getpwuid_r implementation in bionic libc in Android platforms below 19. Just remove the call off the code.
---------------------------
-----------------------------------------------------------------