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# 
相关推荐
alexhilton5 小时前
用Compose中的Shader实现一个雪花飘飘弹窗效果
android·kotlin·android jetpack
iffy15 小时前
安卓录音方法
android
IT古董6 小时前
【第四章:大模型(LLM)】05.LLM实战: 实现GPT2-(6)贪婪编码,temperature及tok原理及实现
android·开发语言·kotlin
安卓机器9 小时前
安卓10.0系统修改定制化____系列 ROM解打包 修改 讲解 导读篇
android·安卓10系统修改
叽哥9 小时前
flutter学习第 14 节:动画与过渡效果
android·flutter·ios
小仙女喂得猪9 小时前
2025再读Android RecyclerView源码
android·android studio
BoomHe9 小时前
车载 XCU 的简单介绍
android
锅拌饭10 小时前
RecyclerView 缓存复用导致动画失效问题
android
程序员老刘10 小时前
操作系统“卡脖子”到底是个啥?
android·开源·操作系统
拭心10 小时前
一键生成 Android 适配不同分辨率尺寸的图片
android·开发语言·javascript