• nodejs的交叉(跨平台)编译(to android)


    nodejs的二进制包有两种安装方式node-gyp以及node-pre-gyp

    这两条命令会写入该包的安装脚本。

    node-gyp是使用gyp工具编译源码,因此必须指定交叉编译器(参见http://n8.io/cross-compiling-nodejs-v0.8/)

    node-pre-gyp首先考虑从package.json定义的远程地址下载二进制包,若无,则依然交给node-gyp编译

    node-pre-gyp指定平台和架构的参数为 --target_platform="" --target_arch=""(参见https://www.npmjs.com/package/node-pre-gyp)

    以上已知后写入脚本。

    例子:

    #设置交叉编译器
    export AR=~/node-v0.12.4/android-toolchain/arm-linux-androideabi/bin/ar
    export 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++
    #定义需要编译的库列表
    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

    注意nodejs的版本是否一致,如果因为node版本不一致导致运行时找不到文件请手工修改路径。工具链的生成看最后一段。

    最后是node的编译

    wget http://nodejs.org/dist/v0.12.4/node-v0.12.4.tar.gz
    tar xvf node-v0.12.4.tar.gz
    cd node-v0.12.4
    sed -i "s/arm-linux-androideabi-4.7/arm-linux-androideabi-4.8/g" android-configure
    source ./android-configure ~/android-ndk-r9d
    cd android-toolchain/bin
    mv python2.7 oldpython2.7 && ln -s /usr/bin/python2.7 python2.7
    cd ../../
    make
    ~/android-ndk-r9d是ndk的路径
    可执行文件为node-v0.12.4/out/Release/node 使用adb push node /data/local/tmp/node 就可以在手机执行

  • 相关阅读:
    class7-附
    class6-附
    class6
    class5-附
    class4-附
    class4
    class3-附【家庭资产配置】
    class2
    芒果绿的blog
    java网络爬虫基础学习(四)
  • 原文地址:https://www.cnblogs.com/XmodYgetZ/p/4580300.html
Copyright © 2020-2023  润新知