nodejs的交叉(跨平台)編譯(to android)

來源:互聯網
上載者:User

標籤:

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/arexport 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.gztar xvf node-v0.12.4.tar.gzcd node-v0.12.4sed -i "s/arm-linux-androideabi-4.7/arm-linux-androideabi-4.8/g" android-configuresource ./android-configure ~/android-ndk-r9dcd android-toolchain/binmv python2.7 oldpython2.7 && ln -s /usr/bin/python2.7 python2.7cd ../../make
~/android-ndk-r9d是ndk的路徑
可執行檔為node-v0.12.4/out/Release/node 使用adb push node /data/local/tmp/node 就可以在手機執行

nodejs的交叉(跨平台)編譯(to android)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.