3 # In order to cross-compile node for Android using NDK, run:
4 # source android-configure <path_to_ndk> [arch]
6 # By running android-configure with source, will allow environment variables to
7 # be persistent in current session. This is useful for installing native node
8 # modules with npm. Also, don't forget to set the arch in npm config using
9 # 'npm config set arch=<arch>'
12 echo "$0 should have 3 parameters: ndk_path, target_arch and sdk_version"
18 ANDROID_SDK_VERSION=$3
20 if [ $ANDROID_SDK_VERSION -lt 23 ]; then
21 echo "$ANDROID_SDK_VERSION should equal or later than 23(Android 6.0)"
29 TOOLCHAIN_NAME="armv7-linux-androideabi"
33 TOOLCHAIN_NAME="i686-linux-android"
37 TOOLCHAIN_NAME="x86_64-linux-android"
42 TOOLCHAIN_NAME="aarch64-linux-android"
46 echo "Unsupported architecture provided: $ARCH"
53 export CC_host=$(which gcc)
54 export CXX_host=$(which g++)
56 host_gcc_version=$($CC_host --version | grep gcc | awk '{print $NF}')
57 major=$(echo $host_gcc_version | awk -F . '{print $1}')
58 minor=$(echo $host_gcc_version | awk -F . '{print $2}')
59 if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || [ $major -eq 6 -a $minor -lt 3 ]; then
60 echo "host gcc $host_gcc_version is too old, need gcc 6.3.0"
64 SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION"
65 TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH
67 export PATH=$TOOLCHAIN/bin:$PATH
68 export CC=$TOOLCHAIN/bin/$SUFFIX-clang
69 export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++
72 GYP_DEFINES="target_arch=$ARCH"
73 GYP_DEFINES+=" v8_target_arch=$ARCH"
74 GYP_DEFINES+=" android_target_arch=$ARCH"
75 GYP_DEFINES+=" host_os=$HOST_OS OS=android"
78 if [ -f "configure" ]; then
80 --dest-cpu=$DEST_CPU \