android 编译 node js 14
2024-10-21 12:41:00
本文基于wsl ubuntu 22.04.1 LTS 系统 上成功编译 安卓版 node js 14.15.4的一些记录.
编译环境:
nodejs 用到两套编译器分别用来编译本机的一些工具链和目标平台的node二进制
1.本机相关环境配置:
下载ndk android-ndk-r23b 解压到~/android-ndk-r23b
python 3.10
安装 gcc 9.40
# by default, build for arm64
HOST_OS="linux"
HOST_ARCH="x86_64"
HOST_GCC_DIR=/usr export CC_host=$HOST_GCC_DIR/bin/gcc
export CXX_host=$HOST_GCC_DIR/bin/g++
export AR_host=$HOST_GCC_DIR/bin/gcc-ar
export RANLIB_host=$HOST_GCC_DIR/bin/gcc-ranlib
export LD_LIBRARY_PATH=$HOST_GCC_DIR/lib64:$LD_LIBRARY_PATH GYP_DEFINES="target_arch=$ARCH"
GYP_DEFINES+=" v8_target_arch=$ARCH"
GYP_DEFINES+=" android_target_arch=$ARCH"
GYP_DEFINES+=" host_os=$HOST_OS OS=android"
export GYP_DEFINES
2.ndk编译配置
export NDK=~/android-ndk-r23b
export ENVSRCTARBALL=""
export HOST_GCC_DIR=""
export ENVDISTBIN="dist"
export ENVHOST=linux-x86_64
export ENVTARGET=aarch64-linux-android
export ENVANDROIDVER=23
export CROSS_COMPILE="--build=x86_64-linux --host=arm-eabi --target=arm-eabi" export COMPILERDIR="$NDK/toolchains/llvm/prebuilt/$ENVHOST/bin"
export CC="$COMPILERDIR/${ENVTARGET}${ENVANDROIDVER}-clang"
export CXX="$COMPILERDIR/${ENVTARGET}${ENVANDROIDVER}-clang++"
export LD="$COMPILERDIR/$ENVTARGET-ld"
export AS="$COMPILERDIR/$ENVTARGET-as"
export AR="$COMPILERDIR/llvm-ar"
export STRIP="$COMPILERDIR/llvm-strip"
export OBJCOPY="$COMPILERDIR/llvm-objcopy"
export OBJDUMP="$COMPILERDIR/llvm-objdump"
export RANLIB="$COMPILERDIR/llvm-ranlib"
export NM="$COMPILERDIR/llvm-nm"
export STRINGS="$COMPILERDIR/llvm-strings"
export READELF="$COMPILERDIR/llvm-readelf"
export ANDROID="$COMPILERDIR/../sysroot"
3.开始编译
./configure \
--prefix=~/node-v14.15.4 \
--dest-cpu=arm64 \
--dest-os=android \
--without-snapshot \
--openssl-no-asm \
--cross-compiling \
--shared
4.编译过程中的一些问题
全文搜索python脚本
grep -r 'from collections import Mapping' ../node-v14.15.4/deps
grep -r 'from collections import Mapping' ../node-v14.15.4/tools
把from collections import Mappin替换为from collections.abc import Mappin
原因是因为pyhton3.10版本高了
5.addon的编译
在同一台机器上安装原生版本的node-v14.14.4 和npm.
安装node-gyp,下面以官方例子为例:
#下载官方例子
git clone https://github.com/nodejs/node-addon-examples.git
#以helloword的为例
cd node-addon-examples/1_hello_world/napi
#修改binding.gyp ,在sources后面添加
# "libraries": [ "-lnode","-L.." ],
#并把libnode.so复制到这个目录下 #生成makefile
node-gyp configure --arch=$DEST_CPU --nodedir=~/node-v14.15.4
#编译
node-gyp build --silly
最新文章
- Chrome浏览器调试,console简述
- 从零点壹开始学JAVA(DAY 1 笔记)<;补充记录>;
- Apache Flink初接触
- (转)postman中 form-data、x-www-form-urlencoded、raw、binary的区别
- disconnected no supported authentication methods available(server sent: publickey,keyboard interae)
- 使用go的ssh包快速打造一个本地命令行ssh客户端
- 学习LCMapString和LCMapStringEx
- VC自动与Internet时间服务器同步更新
- VueJS搭建简单后台管理系统框架 (二) 模拟Ajax数据请求
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
- EF6多线程与分库架构设计之Repository
- Eclipse远程调试应用程序
- recompose mapProps
- Linux学习之路(一)
- 异步操作之 Promise 和 Async await 用法进阶
- 2)django-请求生命周期
- HTTP 02 HTTP1.1 协议
- 安卓listview滚动时背景变黑的解决方法
- Dapper实用教程
- Linus&#39; Law