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


    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 ");
    });

    // 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/");


    ------------------------将其复制到虚拟手机
    [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

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



    --------------------------------------------------------------------------------------------------------------------------
    main reference:  http://www.goland.org/nodejsonandroid/

    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
    阅读(95) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~
    评论热议
  • 相关阅读:
    读Javascript MDN之闭包
    观察者模式小探
    javascript之克隆
    element-vue的简单使用
    页面加载海量数据
    手把手教你入门微信公众号开发
    ES6 Promise 用法讲解
    Javascript模块化编程(三):require.js的用法
    Javascript模块化编程(二):AMD规范
    Javascript模块化编程(一):模块的写法
  • 原文地址:https://www.cnblogs.com/ztguang/p/12648775.html
Copyright © 2020-2023  润新知