编译android版本openssl和curl

OPENSSL编译步骤

源码下载和解压

wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1f.tar.gz
tar -zxvf openssl-1.1.1f.tar.gz

导入ndk环境变量

export ANDROID_NDK_HOME=/home/username/ndk/android-ndk-r20b
export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH

编译arm32位openssl

./Configure android-arm -D__ANDROID_API__=23 --prefix=/home/username/openssl/out/arm/
make clean
make & make install

编译arm64位

./Configure android-arm64 -D__ANDROID_API__=23 --prefix=/home/username/openssl/out/arm64/
make clean
make & make install

--prefix路径:必须先创建

参考链接

https://www.freesion.com/article/6742800401

CURL编译

源码下载和解压

wget https://curl.se/download/curl-7.84.0.tar.gz
tar -xvzf curl-7.84.0.tar.gz

导入NDK编译环境

export NDK=/home/username/ndk/android-ndk-r20b
export HOST_TAG=linux-x86_64 # 按照当前设备环境来
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
export CC=$TOOLCHAIN/bin/aarch64-linux-android29-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android29-clang++
export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip

编译curl

./configure --host aarch64-linux-android --with-pic --disable-shared
make

编译支持https协议curl

# 将openssl编译相关结果内容拷贝至ndk路径
cp -a /home/username/openssl/out/arm64/lib /home/username/ndk/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/

# 如果缺少相关openssl头文件,将头文件openssl/openssl-1.1.1f/include/openssl拷贝至ndk路径下,r20b版本已经包含,忽视本步骤
cp -a /home/username/openssl/openssl-1.1.1f/include/openssl /home/username/ndk/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include

编译curl (支持https)

./configure --host aarch64-linux-android --with-pic --disable-shared --with-openssl="${TOOLCHAIN}/sysroot/usr"
make

输出curl在当前curl源码路径下src/curl

注意事项

在android 8.1系统上,如果要使用支持https的curl,必须先支持openssl

参考链接

https://curl.se/docs/install.html

你可能感兴趣的:(编译android版本openssl和curl)