1. 下載Linux平臺下的NDK軟件包?
NDK 下載 ?|? Android NDK ?|? Android Developers
下載完成后執行解壓命令
# unzip android-ndk-r27d-linux.zip
2.?下載openssl-1.1.1w源碼包,并解壓
# tar -xzvf openssl-1.1.1w.tar.gz
3.?進入解壓后的openssl-1.1.1w目錄
執行以下操作:
3.1?修改下面的Android配置文件
#vi Configurations/15-android.conf??
my %targets = ("android" => {inherit_from => [ "linux-generic32" ],template => 1,################################################################# Special note about -pie. The underlying reason is that# Lollipop refuses to run non-PIE. But what about older systems# and NDKs? -fPIC was never problem, so the only concern is -pie.# Older toolchains, e.g. r4, appear to handle it and binaries# turn out mostly functional. "Mostly" means that oldest# Androids, such as Froyo, fail to handle executable, but newer# systems are perfectly capable of executing binaries targeting# Froyo. Keep in mind that in the nutshell Android builds are# about JNI, i.e. shared libraries, not applications.cflags => add(sub { android_ndk()->{cflags} }),cppflags => add(sub { android_ndk()->{cppflags} }),cxxflags => add(sub { android_ndk()->{cflags} }),bn_ops => sub { android_ndk()->{bn_ops} },bin_cflags => "-pie",enable => [ ],shared_extension => ".so", ###增加這行},
3.2? 配置和編譯
# export ANDROID_NDK_HOME=/home/llw/android-ndk-r27d/
# 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
# ./Configure android-arm64 -D__ANDROID_API__=26
# make clean
# make
編譯完成后在目錄下面生成了所需要的兩個動態庫,?通過查看文件屬性發現得到的是64位的arm架構的動態庫?
root@lf-virtual-machine:/home/llw/openssl-1.1.1w#
root@lf-virtual-machine:/home/llw/openssl-1.1.1w# file libssl.so
libssl.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
root@lf-virtual-machine:/home/llw/openssl-1.1.1w#
root@lf-virtual-machine:/home/llw/openssl-1.1.1w# file libcrypto.so
libcrypto.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
root@lf-virtual-machine:/home/llw/openssl-1.1.1w#
root@lf-virtual-machine:/home/llw/openssl-1.1.1w#
root@lf-virtual-machine:/home/llw/openssl-1.1.1w#
優化動態庫的體積大小?
root@lf-virtual-machine:/home/llw/openssl-1.1.1w# llvm-strip --strip-unneeded libcrypto.so
root@lf-virtual-machine:/home/llw/openssl-1.1.1w# ls -alth *.so
-rwxr-xr-x 1 root root 2.6M Jul 16 16:23 libcrypto.so
-rwxr-xr-x 1 root root 657K Jul 16 15:29 libssl.so
root@lf-virtual-machine:/home/llw/openssl-1.1.1w# llvm-strip --strip-unneeded libssl.so
root@lf-virtual-machine:/home/llw/openssl-1.1.1w# ls -alth *.so
-rwxr-xr-x 1 root root 569K Jul 16 16:24 libssl.so
-rwxr-xr-x 1 root root 2.6M Jul 16 16:23 libcrypto.so
root@lf-virtual-machine:/home/llw/openssl-1.1.1w#