Android平台下openssl动态库编译

  1. 下载Linux平台下的NDK软件包

NDK 下载 | Android NDK | Android Developers

下载完成后执行解压命令

bash 复制代码
# unzip android-ndk-r27d-linux.zip
  1. 下载openssl-1.1.1w源码包,并解压
bash 复制代码
# tar -xzvf openssl-1.1.1w.tar.gz 
  1. 进入解压后的openssl-1.1.1w目录

执行以下操作:

3.1 修改下面的Android配置文件

#vi Configurations/15-android.conf

bash 复制代码
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 配置和编译

bash 复制代码
# 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架构的动态库

bash 复制代码
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# 

优化动态库的体积大小

bash 复制代码
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# 
相关推荐
消失的旧时光-194314 小时前
kmp需要技能
android·设计模式·kotlin
帅得不敢出门15 小时前
Linux服务器编译android报no space left on device导致失败的定位解决
android·linux·服务器
雨白16 小时前
协程间的通信管道 —— Kotlin Channel 详解
android·kotlin
TimeFine18 小时前
kotlin协程 容易被忽视的CompletableDeferred
android
czhc114007566319 小时前
Linux1023 mysql 修改密码等
android·mysql·adb
GOATLong20 小时前
MySQL内置函数
android·数据库·c++·vscode·mysql
onthewaying21 小时前
Android SurfaceTexture 深度解析
android·opengl
茄子凉心21 小时前
Android Bluetooth 蓝牙通信
android·蓝牙通信·bluetooth通信
00后程序员张1 天前
iOS 26 App 运行状况全面解析 多工具协同监控与调试实战指南
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
iOS 混淆实战,多工具组合完成 IPA 混淆、加固与发布治理(iOS混淆|IPA加固|无源码混淆|App 防反编译)
android·ios·小程序·https·uni-app·iphone·webview