Android:Linux交叉编译Python3,生成安卓可执行文件
1、下载Python最新版本3.8文件
2、编译脚本:
#!/bin/bash
COMPILE_ROOT=`pwd`
ANDROID_NDK_ROOT=~/ndk/android-ndk-r20
ANDROID_GCC_ROOT=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64
ANDROID_GCC_PATH=${ANDROID_GCC_ROOT}/bin
BUILD_PATH=${COMPILE_ROOT}/build
OUT_PATH=${COMPILE_ROOT}/out
OPENSSL_PATH=${COMPILE_ROOT}/thirdparty/libressl-2.7.4/out
OPENSSL_LIB_PATH=${COMPILE_ROOT}/thirdparty/libressl-2.7.4/out/lib
CROSS_COMPILER=aarch64-linux-android-
CROSS_COMPILER_CLANG=aarch64-linux-android28-
#prepare
mkdir -p ${BUILD_PATH}
mkdir -p ${OUT_PATH}
export PATH=${ANDROID_NDK_ROOT}:${ANDROID_GCC_PATH}:$PATH
export ARCH="aarch64"
export CC="${CROSS_COMPILER_CLANG}clang -pie -fPIE"
export CPP="${CROSS_COMPILER_CLANG}clang -E -pie -fPIE"
export CXX="${CROSS_COMPILER_CLANG}clang++ -pie -fPIE"
export AS="${CROSS_COMPILER}as"
export LD="${CROSS_COMPILER}ld -pie -fPIE"
export GDB="${CROSS_COMPILER}gdb"
export STRIP="${CROSS_COMPILER}strip"
export RANLIB="${CROSS_COMPILER}ranlib"
export OBJCOPY="${CROSS_COMPILER}objcopy"
export OBJDUMP="${CROSS_COMPILER}objdump"
export AR="${CROSS_COMPILER}ar"
export NM="${CROSS_COMPILER}nm"
export READELF="${CROSS_COMPILER}readelf"
export M4=m4
export TARGET_PREFIX=$CROSS_COMPILER
export CONFIG_SITE="config.site"
export CXXFLAGS="-D__ANDROID_API__=28 "
cd ${BUILD_PATH}
echo -e "ac_cv_file__dev_ptmx=yes\nac_cv_file__dev_ptc=no" > config.site
../configure --host=aarch64-linux-android \
--host=aarch64-linux \
--build=x86_64-pc-linux-gnu \
--target=aarch64-linux-android \
LDFLAGS="-Wl,--allow-shlib-undefined -D__ANDROID_API__=28 -fPIC -L${OPENSSL_LIB_PATH}" \
CFLAGS="-D__ANDROID_API__=28 " \
CPPFLAGS="-D__ANDROID_API__=28" \
--enable-shared \
--enable-ipv6 \
--with-openssl=${OPENSSL_PATH} \
--prefix=${OUT_PATH}
make -j8 2>&1 |tee build.log
echo "-----------build success!-------------"
注意: 大家在使用时候注意自己的ndk所在路径,按自己的实际情况进行修改,我的ndk存放在自己的home目录下。