Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6684802
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: Android平台

2015-07-12 20:34:34

Port Node.js to Android running on Genymotion Emulator (x86)

环境:CentOS7 + Genymotion + Google Nexus 5 - 5.10 - API22 - 1080*1920

---1---------------------------------------------------------------------------------------------------------------------
下载 node-v0.12.7.tar.gz , 解压 #tar -xzf node-v0.12.7.tar.gz
位置:/opt/android-on-linux/node/node-v0.12.7/android-configure


---2---------------------------------------------------------------------------------------------------------------------
[root@localhost node-v0.12.7]#  gedit android-configure
--------------------------------------------------------------------------------------------------------------------------
#!/bin/bash

export TOOLCHAIN=$PWD/android-toolchain
mkdir -p $TOOLCHAIN
$1/build/tools/make-standalone-toolchain.sh \
    --toolchain=x86-4.9 \
    --arch=x86 \
    --install-dir=$TOOLCHAIN \
    --platform=android-9
export PATH=$TOOLCHAIN/bin:$PATH
export AR=i686-linux-android-ar
export CC='i686-linux-android-gcc -pie -fPIE'
export CXX='i686-linux-android-g++ -pie -fPIE'
export LINK='i686-linux-android-g++ -pie -fPIE'

./configure \
    --without-snapshot \
    --dest-cpu=ia32 \
    --dest-os=android


---3---------------------------------------------------------------------------------------------------------------------
进入: /opt/android-on-linux/node/node-v0.12.7/android-toolchain/bin
执行如下命令:
[root@localhost bin]# mv python2.7 oldpython2.7 && ln -s /usr/bin/python2.7 python2.7


---4---------------------------------------------------------------------------------------------------------------------
Run from inside of ~/node directory
[root@localhost node-v0.12.7]# source ./android-configure /opt/android-on-linux/android-ndk-r10d
[root@localhost node-v0.12.7]# make -j4


---5---------------------------------------------------------------------------------------------------------------------
[root@localhost node-v0.12.7]#  /opt/android-on-linux/node/node-v0.12.7/deps/uv/src/core.c
--------------------------------------------------------------------------------------------------------------------------
注释如下几行:
    r = getpwuid_r(uid, &pw, buf, bufsize, &result);

    if (r != ERANGE)
      break;


---6---------------------------------------------------------------------------------------------------------------------
[root@localhost node-v0.12.7]# make -j4


---7---------------------------------------------------------------------------------------------------------------------
至此,编译node.js成功,即生成:/opt/android-on-linux/node/node-v0.12.7/out/Release/node


---8---------------------------------------------------------------------------------------------------------------------
环境:CentOS7 + Genymotion + Google Nexus 5 - 5.10 - API22 - 1080*1920
# gedit ~/.bashrc

PATH=$PATH:$HOME/bin
PATH=$PATH:/opt/android-on-linux/node/node-v0.12.7/android-toolchain/bin
# provide ndk-build
PATH=$PATH:/opt/android-on-linux/android-ndk-r10d
# provide adb
PATH=$PATH:/opt/android-on-linux/android-sdk-linux/platform-tools
export PATH


---9---------------------------------------------------------------------------------------------------------------------
Release文件夹大小:82.8M,将其(node)复制到虚拟手机
进入:/opt/android-on-linux/node/node-v0.12.7/out/

[root@localhost out]# adb push Release /data/local/tmp/Release


---10-------------------------------------------------------------------------------------------------------------------
在CentOS7 编辑文件:/opt/android-on-linux/android-project/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 );


------------------------将其复制到虚拟手机
[root@localhost android-project]# adb push helloworld.js /data/local/tmp


---12-------------------------------------------------------------------------------------------------------------------
在虚拟手机
[root@localhost out]# adb shell
root@vbox86p:/ # chmod 700 /data/local/tmp/Release/node                                                     
root@vbox86p:/ # /data/local/tmp/Release/node /data/local/tmp/helloworld.js

然后,在浏览器地址栏输入: ,即可访问



--------------------------------------------------------------------------------------------------------------------------
main reference: 管理员在2009年8月13日编辑了该文章文章。
-->
阅读(915) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~