Android开发编译curl库给Android使用
- 编译zlib库
官网:http://zlib.net/
解决后面出现的error: --with-openssl was given but OpenSSL could not be detected
export ANDROID_NDK_HOME=/home/ubuntu20/Android/Sdk/ndk/21.4.7075529
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64
export AR=$TOOLCHAIN/bin/llvm-ar
export AS=$TOOLCHAIN/bin/llvm-as
export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
wget http://zlib.net/zlib-1.3.1.tar.gz
tar -zxvf zlib-1.3.1.tar.gz
cd zlib-1.3.1
mkdir build_out
./configure --prefix=/home/ubuntu20/documents/zlib-1.3.1/build_out
make clean
make
make install
- 编译openssl库
export ANDROID_NDK_ROOT=/home/ubuntu20/Android/Sdk/ndk/21.4.7075529
PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
wget https://github.com/openssl/openssl/releases/download/openssl-3.3.2/openssl-3.3.2.tar.gz
tar -zxvf openssl-3.3.2.tar.gz
cd openssl-3.3.2
mkdir build_out
./Configure android-arm64 no-unit-test -D__ANDROID_API__=21 --prefix=/home/ubuntu20/documents/openssl-3.3.2/build_out
#32位使用./Configure android-arm no-unit-test -D__ANDROID_API__=21 --prefix=/home/ubuntu20/documents/openssl-3.3.2/build_out
make clean
make
make install
- 编译psl库,
如果不想使用这个库,编译curl的时候传递--without-libpsl
如果要使用这个库,编译curl的时候传递--with-libpsl=/home/ubuntu20/documents/libpsl-0.21.5/build 指定libpsl库pkgconfig路径
官网:https://www.linuxfromscratch.org/blfs/view/svn/basicnet/libpsl.html
Github地址:https://github.com/rockdaboot/libpsl
编译psl库我使用了官网说的meson和ninjia编译,有一点点麻烦,只要是android交叉编译要指定--cross-file cross_file.txt
cross_file.txt内容要指定[host_machine]部分
[host_machine]
system = 'aarch64-linux-android'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'
wget https://github.com/rockdaboot/libpsl/releases/download/0.21.5/libpsl-0.21.5.tar.gz
tar -zxvf libpsl-0.21.5.tar.gz
cd libpsl-0.21.5
mkdir build_out
meson setup --prefix=/home/ubuntu20/documents/libpsl-0.21.5/build_out --buildtype=release --cross-file cross_file.txt
ninja //找到Android sdk下的ninjia,/home/ubuntu20/Android/Sdk/cmake/3.22.1/bin/ninja
ninja install
- 编译curl库
官网:https://curl.se/docs/install.html
Github地址:https://github.com/curl/curl
export ANDROID_NDK_HOME=/home/ubuntu20/Android/Sdk/ndk/21.4.7075529
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64
export AR=$TOOLCHAIN/bin/llvm-ar
export AS=$TOOLCHAIN/bin/llvm-as
export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
wget https://github.com/curl/curl/releases/download/curl-8_10_0/curl-8.10.0.tar.gz
tar curl-8.10.0.tar.gz
cd curl-8.10.0
mkdir build_out
//官网也没提高编译android动态库的指令,估计curl编译不了Android下的动态库,只能编译出静态库
//如果不使用libpsl,则--with-libpsl=xxx改为--without-libpsl,才能配置成功
//编译32位的话使用--host=armv7a-linux-androideabi
./configure --host=aarch64-linux-android --prefix=/home/ubuntu20/documents/curl/curl-8.10.0/build_out --with-zlib=/home/ubuntu20/documents/zlib-1.3.1/build_out --with-openssl=/home/ubuntu20/documents/openssl-3.3.2/build_out --with-libpsl=/home/ubuntu20/documents/libpsl-0.21.5/build_out --with-pic --disable-shared --enable-static
make clean
make
make install
Android常用架构以及架构名称
aarch64-linux-android arm64-v8a android-arm64 //arm64位
armv7a-linux-androideabi armeabi-v7a android-arm //arm32位
i686-linux-android x86 android-x86 //x86 32位
x86_64-linux-android x86_64 android-x86_64 //x86 64位
标签:bin,TOOLCHAIN,--,编译,export,linux,Android,curl
From: https://www.cnblogs.com/yongfengnice/p/18463856