-
(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/bashexport TOOLCHAIN=$PWD/android-toolchainmkdir -p $TOOLCHAIN$1/build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.9 --arch=arm --install-dir=$TOOLCHAIN --platform=android-14export PATH=$TOOLCHAIN/bin:$PATHexport AR=$TOOLCHAIN/bin/arm-linux-androideabi-arexport CC=$TOOLCHAIN/bin/arm-linux-androideabi-gccexport 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]# lsarm-linux-androideabi-addr2line arm-linux-androideabi-gcc arm-linux-androideabi-ld arm-linux-androideabi-sizearm-linux-androideabi-ar arm-linux-androideabi-gcc-4.9 arm-linux-androideabi-ld.bfd arm-linux-androideabi-stringsarm-linux-androideabi-as arm-linux-androideabi-gcc-ar arm-linux-androideabi-ld.gold arm-linux-androideabi-striparm-linux-androideabi-c++ arm-linux-androideabi-gcc-nm arm-linux-androideabi-ld.mcld pythonarm-linux-androideabi-c++filt arm-linux-androideabi-gcc-ranlib arm-linux-androideabi-nm python2arm-linux-androideabi-cpp arm-linux-androideabi-gcov arm-linux-androideabi-objcopy python2.7arm-linux-androideabi-dwp arm-linux-androideabi-gcov-tool arm-linux-androideabi-objdumparm-linux-androideabi-elfedit arm-linux-androideabi-gdb arm-linux-androideabi-ranlibarm-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/Releaseroot@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/Releaseroot@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
");});// Listen on port 8000, IP defaults to 127.0.0.1server.listen(8000);// Put a friendly message on the terminalconsole.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-21Answer 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 welcomeAnswer 2:There is no getpwuid_r implementation in bionic libc in Android platforms below 19. Just remove the call off the code.--------------------------------------------------------------------------------------------
-
相关阅读:
c#委托总结
架构研究一(autofac 注册路由 )
Fedora20 和ubuntu 14.04 chrome标签中文乱码
Fedora20 编译安装qemu-system
NFS安装配置
Mysql自动备份脚本
Mysql性能调优(my.cnf参数篇)
Mysql性能基本测试
mysql编译安装主从复制
Mysql 配置参数详解以及优化配置
-
原文地址:https://www.cnblogs.com/ztguang/p/12647133.html
Copyright © 2020-2023
润新知