最近因为需要,编译了一下openssl的最新版本。记录下编译过程跟完整的编译脚本。
一、准备工作
- android-ndk-r13b
- openssl-1.1.0f.tar.gz
二、开始编译
参考了: https://github.com/leenjewel/openssl_for_ios_and_android/tree/master/tools 里面的脚本,修改了一点。
主要是加入了compileAll.sh, 以及去掉soname。
因为我要用的位libssl.so、libcrypto.so共享库。因此需要注释这一行。
这里是让生成的so里面的库文件名没有后缀、soversion, 不然在安卓上无法用。最终生成的so, readelf查看如下:
然后,写了一个compileAll.sh
#!/bin/bash
export ANDROID_NDK=~/Android/android-ndk-r13b
currentPath=`pwd`
destDir="编译好的libs"
rm -rf $currentPath/$destDir
mkdir $currentPath/$destDir
for i in android android-armeabi android64-aarch64 android-x86 android64
do
rm -rf $currentPath/{arm64-v8a, armeabi, armeabi-v7a, x86_64, x86}-toolchain
rm -rf $currentPath/libs
cd $currentPath
echo "开始编译"
echo $i
if [ "$i" = "android64-aarch64" ]; then
ANDROID_API=21 bash ./build-openssl4android.sh $i > /dev/null 2&>1
elif [ "$i" = "x86_64" ]; then
ANDROID_API=21 bash ./build-openssl4android.sh $i > /dev/null 2&>1
else
ANDROID_API=9 bash ./build-openssl4android.sh $i > /dev/null 2&>1
fi
unset ANDROID_API
for j in libssl libcrypto
do
echo $currentPath/openssl-1.1.0f/$j.so
echo `find $currentPath/libs/ -name $j.a`
mv $currentPath/openssl-1.1.0f/$j.so `find $currentPath/libs/ -name $j.a|xargs dirname`/
done
cd $currentPath/$destDir && cp -r $currentPath/libs/* .
echo $i
echo "编译完成"
done
执行 ./compileAll.sh 即可生成带有动态库、静态库的五种架构的ndk openssl库了。
如果想编译libevent, linux版本的库。
./Configure linux-aarch64 \
--prefix=/home/dengpan/tmp/openssl-linux \
zlib \
no-asm \
no-unit-test
#delete soname, soversion
sed 's/LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR)//g' Makefile | sed 's/.$ (SHLIB_MAJOR).$(SHLIB_MINOR)//g' > Makefile2
mv -f Makefile2 Makefile
make -j10
make install
三、编译脚本、编译好的库下载
- 完整的编译脚本目录, 完整的编译脚本下载
- 完整的openssl压缩库, 完整的openssl-1.1.0f ndk prebuilt包下载