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庫
官網:https://openssl-library.org/source/
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位