【Android音视频】MacOS上OpenSSL3.0.4编译

1. OpenSSL官网下载链接:

openssl源码下载链接icon-default.png?t=M5H6https://www.openssl.org/source/可以看到目前有两个版本的OpenSSL:

【Android音视频】MacOS上OpenSSL3.0.4编译_第1张图片

 2. 下载3.0.4版本压缩包,解压至自己想要的文件路径下即可。以下多步骤为雷同的做法,参考此文即可。【Android音视频】MacOS上FFmpeg5.0.1编译icon-default.png?t=M5H6https://blog.csdn.net/Taozi825232603/article/details/1254365133. 在该OpenSSL文件夹下创建编译脚本,可参考以下脚本(文件名自定义即可,例如 build_openssl.sh)。在编写脚本之前,请你打开目录下的Configure文件查看一下内容,这很有帮助。稍微快速的浏览,你会看到以下这段话:

# All the "make variables" we support
# Some get pre-populated for the sake of backward compatibility
# (we supported those before the change to "make variable" support.
my %user = (
    AR          => env('AR'),
    ARFLAGS     => [],
    AS          => undef,
    ASFLAGS     => [],
    CC          => env('CC'),
    CFLAGS      => [ env('CFLAGS') || () ],
    CXX         => env('CXX'),
    CXXFLAGS    => [ env('CXXFLAGS') || () ],
    CPP         => undef,
    CPPFLAGS    => [ env('CPPFLAGS') || () ],  # -D, -I, -Wp,
    CPPDEFINES  => [],  # Alternative for -D
    CPPINCLUDES => [],  # Alternative for -I
    CROSS_COMPILE => env('CROSS_COMPILE'),
    HASHBANGPERL=> env('HASHBANGPERL') || env('PERL'),
    LD          => undef,
    LDFLAGS     => [ env('LDFLAGS') || () ],  # -L, -Wl,
    LDLIBS      => [ env('LDLIBS') || () ],  # -l
    MT          => undef,
    MTFLAGS     => [],
    PERL        => env('PERL') || ($^O ne "VMS" ? $^X : "perl"),
    RANLIB      => env('RANLIB'),
    RC          => env('RC') || env('WINDRES'),
    RCFLAGS     => [ env('RCFLAGS') || () ],
    RM          => undef,
   );

4. 编写build_openssl.sh文件,大致可参考官方教程(NOTES-ANDROID.md文件),里面说在Linux平台下交叉编译是OK的,但是在别的平台并没测试过。那我们就稍微试试吧(其实用C编译器即可),此处我的测试用手机为 arm64-v8a,因此使用对应的配置参数 android-arm64

#!/bin/bash

export ANDROID_NDK_ROOT=/Users/tao/Library/Android/sdk/ndk/21.4.7075529
export TOOLCHAIN=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64
export CROSS_COMPILE=$TOOLCHAIN/bin/

API=28

export CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++

# note:
# Redmi7(arm64-v8a)
ARCH=arm64
CPU=armv8-a

PREFIX=$(pwd)/android/$CPU

make clean

function build_android
{
    echo "Compile OpenSSL start."

    ./Configure \
    android-arm64 \
    -D__ANDROID_API__=$API \
    --prefix=$PREFIX 

    make clean
    make -j8
    make install

    echo "Compile OpenSSL completed."
}

build_android

5. 开始编译OpenSSL。执行(本人将该文件名命名为 build_openssl.sh):

./build_openssl.sh

6. 编译完成后,可在该OpenSSL文件夹下看到 android 文件夹,里面有我们需要的 include 和 lib文件夹。


至此,OpenSSL3.0.4编译完成。

你可能感兴趣的:(Enjoy,Android,android,ssl)