1 概述

openssl可以编译成ARM下面的二进制代码(动态库或者静态库),方便APP使用,APP在使用的时候,需要使用JNI来进行调用。

本文章参考官方文档https://wiki.openssl.org/index.php/Android进行总结。

编译步骤:

1.下载NDK

2.下载openssl和setenv-android.sh

3.设置环境变量,配置openssl

4.编译

2 下载NDK

我使用的是SUSE Linux环境,首先需要下载NDK。地址:https://developer.android.com/ndk/downloads/,根据自己需要下载相应的版本,我这里使用的是android-ndk-r16b-linux-x86_64.zip,下载后进行解压。

wangning@SZX1000291132:/home/clouddragon/packages/tmp> unzip android-ndk-r16b-linux-x86_64.zip

3 下载openssl

下载openssl地址:https://github.com/openssl/openssl/releases。根据自己需要下载相应的版本,我使用的是openssl-OpenSSL_1_1_0g.tar.gz,下载后进行解压。

wangning@SZX1000291132:/home/clouddragon/packages/tmp> tar -xzf openssl-OpenSSL_1_1_0g.tar.gz

下载setenv-android.sh并根据自己需要进行相应变量的修改。

64位版本:setenv-android_64.sh

#! /bin/bash
# Cross-compile environment for Android on ARMv7 and x86
#
# Contents licensed under the terms of the OpenSSL license
# http://www.openssl.org/source/license.html
#
# See http://wiki.openssl.org/index.php/FIPS_Library_and_Android
#   and http://wiki.openssl.org/index.php/Android#####################################################################
export ANDROID_NDK_HOME=/home/clouddragon/packages/tmp/android-ndk-r16b
export ANDROID_NDK_ROOT=/home/clouddragon/packages/tmp/android-ndk-r16b
# Set ANDROID_NDK_ROOT to you NDK location. For example,
# /opt/android-ndk-r8e or /opt/android-ndk-r9. This can be done in a
# login script. If ANDROID_NDK_ROOT is not specified, the script will
# try to pick it up with the value of _ANDROID_NDK_ROOT below. If
# ANDROID_NDK_ROOT is set, then the value is ignored.
# _ANDROID_NDK="android-ndk-r8e"
_ANDROID_NDK="android-ndk-r16b"
# _ANDROID_NDK="android-ndk-r10"# Set _ANDROID_EABI to the EABI you want to use. You can find the
# list in $ANDROID_NDK_ROOT/toolchains. This value is always used.
# _ANDROID_EABI="x86-4.6"
# _ANDROID_EABI="arm-linux-androideabi-4.6"
_ANDROID_EABI="arm-linux-androideabi-4.9"# Set _ANDROID_ARCH to the architecture you are building for.
# This value is always used.
# _ANDROID_ARCH=arch-x86
_ANDROID_ARCH=arch-arm# Set _ANDROID_API to the API you want to use. You should set it
# to one of: android-14, android-9, android-8, android-14, android-5
# android-4, or android-3. You can't set it to the latest (for
# example, API-17) because the NDK does not supply the platform. At
# Android 5.0, there will likely be another platform added (android-22?).
# This value is always used.
# _ANDROID_API="android-14"
_ANDROID_API="android-24"
# _ANDROID_API="android-19"###################################################################### If the user did not specify the NDK location, try and pick it up.
# We expect something like ANDROID_NDK_ROOT=/opt/android-ndk-r8e
# or ANDROID_NDK_ROOT=/usr/local/android-ndk-r8e.if [ -z "$ANDROID_NDK_ROOT" ]; then_ANDROID_NDK_ROOT=""if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="/usr/local/$_ANDROID_NDK"fiif [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="/opt/$_ANDROID_NDK"fiif [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="$HOME/$_ANDROID_NDK"fiif [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="$PWD/$_ANDROID_NDK"fi# If a path was set, then export itif [ ! -z "$_ANDROID_NDK_ROOT" ] && [ -d "$_ANDROID_NDK_ROOT" ]; thenexport ANDROID_NDK_ROOT="$_ANDROID_NDK_ROOT"fi
fi# Error checking
# ANDROID_NDK_ROOT should always be set by the user (even when not running this script)
# http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77
if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; thenecho "Error: ANDROID_NDK_ROOT is not a valid path. Please edit this script."# echo "$ANDROID_NDK_ROOT"# exit 1
fi# Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; thenecho "Error: ANDROID_NDK_ROOT/toolchains is not a valid path. Please edit this script."# echo "$ANDROID_NDK_ROOT/toolchains"# exit 1
fi# Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" ]; thenecho "Error: ANDROID_EABI is not a valid path. Please edit this script."# echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI"# exit 1
fi###################################################################### Based on ANDROID_NDK_ROOT, try and pick up the required toolchain. We expect something like:
# /opt/android-ndk-r83/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin
# Once we locate the toolchain, we add it to the PATH. Note: this is the 'hard way' of
# doing things according to the NDK documentation for Ice Cream Sandwich.
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.htmlANDROID_TOOLCHAIN=""
for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
doif [ -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; thenANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin"breakfi
done# Error checking
if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; thenecho "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script."# echo "$ANDROID_TOOLCHAIN"# exit 1
ficase $_ANDROID_ARCH inarch-arm)     ANDROID_TOOLS="arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld";;arch-x86)   ANDROID_TOOLS="i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld";;     *)echo "ERROR ERROR ERROR";;
esacfor tool in $ANDROID_TOOLS
do# Error checkingif [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; thenecho "Error: Failed to find $tool. Please edit this script."# echo "$ANDROID_TOOLCHAIN/$tool"# exit 1fi
done# Only modify/export PATH if ANDROID_TOOLCHAIN good
if [ ! -z "$ANDROID_TOOLCHAIN" ]; thenexport ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN"export PATH="$ANDROID_TOOLCHAIN":"$PATH"
fi###################################################################### For the Android SYSROOT. Can be used on the command line with --sysroot
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
export CROSS_SYSROOT="$ANDROID_SYSROOT"
export NDK_SYSROOT="$ANDROID_SYSROOT"# Error checking
if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; thenecho "Error: ANDROID_SYSROOT is not valid. Please edit this script."# echo "$ANDROID_SYSROOT"# exit 1
fi###################################################################### If the user did not specify the FIPS_SIG location, try and pick it up
# If the user specified a bad location, then try and pick it up too.
if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then# Try and locate it_FIPS_SIG=""if [ -d "/usr/local/ssl/$_ANDROID_API" ]; then_FIPS_SIG=`find "/usr/local/ssl/$_ANDROID_API" -name incore`fiif [ ! -e "$_FIPS_SIG" ]; then_FIPS_SIG=`find $PWD -name incore`fi# If a path was set, then export itif [ ! -z "$_FIPS_SIG" ] && [ -e "$_FIPS_SIG" ]; thenexport FIPS_SIG="$_FIPS_SIG"fi
fi# Error checking. Its OK to ignore this if you are *not* building for FIPS
if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; thenecho "Error: FIPS_SIG does not specify incore module. Please edit this script."# echo "$FIPS_SIG"# exit 1
fi###################################################################### Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored.
export MACHINE=armv7
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=aarch64
export CROSS_COMPILE="arm-linux-androideabi-"#export AR=aarch64-linux-android-ar
export AS=aarch64-linux-android-as
#export CC=aarch64-linux-android-gcc
export CXX=aarch64-linux-android-g++
export LD=aarch64-linux-android-ld
export NM=aarch64-linux-android-nm
export RANLIB=aarch64-linux-android-ranlib
export STRIP=aarch64-linux-android-stripif [ "$_ANDROID_ARCH" == "arch-x86" ]; thenexport MACHINE=i686export RELEASE=2.6.37export SYSTEM=androidexport ARCH=x86export CROSS_COMPILE="i686-linux-android-"
fi# For the Android toolchain
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
export SYSROOT="$ANDROID_SYSROOT"
export NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_API="$_ANDROID_API"# CROSS_COMPILE and ANDROID_DEV are DFW (Don't Fiddle With). Its used by OpenSSL build system.
# export CROSS_COMPILE="arm-linux-androideabi-"
export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"
export HOSTCC=gccVERBOSE=1
if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; thenecho "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"echo "ANDROID_ARCH: $_ANDROID_ARCH"echo "ANDROID_EABI: $_ANDROID_EABI"echo "ANDROID_API: $ANDROID_API"echo "ANDROID_SYSROOT: $ANDROID_SYSROOT"echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN"echo "FIPS_SIG: $FIPS_SIG"echo "CROSS_COMPILE: $CROSS_COMPILE"echo "ANDROID_DEV: $ANDROID_DEV"echo "ARCH: $ARCH"echo "AR: $AR"echo "AS: $AS"echo "CC: $CC"echo "CXX: CXX"echo "LD: $LD"echo "NM: $NM"echo "RANLIB: $RANLIB"echo "STRIP: $STRIP"
fi

32位版本setenv-android_32.sh:

#! /bin/bash
# Cross-compile environment for Android on ARMv7 and x86
#
# Contents licensed under the terms of the OpenSSL license
# http://www.openssl.org/source/license.html
#
# See http://wiki.openssl.org/index.php/FIPS_Library_and_Android
#   and http://wiki.openssl.org/index.php/Android#####################################################################
export ANDROID_NDK_HOME=/home/clouddragon/packages/tmp/android-ndk-r16b
export ANDROID_NDK_ROOT=/home/clouddragon/packages/tmp/android-ndk-r16b
# Set ANDROID_NDK_ROOT to you NDK location. For example,
# /opt/android-ndk-r8e or /opt/android-ndk-r9. This can be done in a
# login script. If ANDROID_NDK_ROOT is not specified, the script will
# try to pick it up with the value of _ANDROID_NDK_ROOT below. If
# ANDROID_NDK_ROOT is set, then the value is ignored.
# _ANDROID_NDK="android-ndk-r8e"
_ANDROID_NDK="android-ndk-r16b"
# _ANDROID_NDK="android-ndk-r10"# Set _ANDROID_EABI to the EABI you want to use. You can find the
# list in $ANDROID_NDK_ROOT/toolchains. This value is always used.
# _ANDROID_EABI="x86-4.6"
# _ANDROID_EABI="arm-linux-androideabi-4.6"
_ANDROID_EABI="arm-linux-androideabi-4.9"# Set _ANDROID_ARCH to the architecture you are building for.
# This value is always used.
# _ANDROID_ARCH=arch-x86
_ANDROID_ARCH=arch-arm# Set _ANDROID_API to the API you want to use. You should set it
# to one of: android-14, android-9, android-8, android-14, android-5
# android-4, or android-3. You can't set it to the latest (for
# example, API-17) because the NDK does not supply the platform. At
# Android 5.0, there will likely be another platform added (android-22?).
# This value is always used.
# _ANDROID_API="android-14"
_ANDROID_API="android-24"
# _ANDROID_API="android-19"###################################################################### If the user did not specify the NDK location, try and pick it up.
# We expect something like ANDROID_NDK_ROOT=/opt/android-ndk-r8e
# or ANDROID_NDK_ROOT=/usr/local/android-ndk-r8e.if [ -z "$ANDROID_NDK_ROOT" ]; then_ANDROID_NDK_ROOT=""if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="/usr/local/$_ANDROID_NDK"fiif [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="/opt/$_ANDROID_NDK"fiif [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="$HOME/$_ANDROID_NDK"fiif [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then_ANDROID_NDK_ROOT="$PWD/$_ANDROID_NDK"fi# If a path was set, then export itif [ ! -z "$_ANDROID_NDK_ROOT" ] && [ -d "$_ANDROID_NDK_ROOT" ]; thenexport ANDROID_NDK_ROOT="$_ANDROID_NDK_ROOT"fi
fi# Error checking
# ANDROID_NDK_ROOT should always be set by the user (even when not running this script)
# http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77
if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; thenecho "Error: ANDROID_NDK_ROOT is not a valid path. Please edit this script."# echo "$ANDROID_NDK_ROOT"# exit 1
fi# Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; thenecho "Error: ANDROID_NDK_ROOT/toolchains is not a valid path. Please edit this script."# echo "$ANDROID_NDK_ROOT/toolchains"# exit 1
fi# Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" ]; thenecho "Error: ANDROID_EABI is not a valid path. Please edit this script."# echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI"# exit 1
fi###################################################################### Based on ANDROID_NDK_ROOT, try and pick up the required toolchain. We expect something like:
# /opt/android-ndk-r83/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin
# Once we locate the toolchain, we add it to the PATH. Note: this is the 'hard way' of
# doing things according to the NDK documentation for Ice Cream Sandwich.
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.htmlANDROID_TOOLCHAIN=""
for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
doif [ -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; thenANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin"breakfi
done# Error checking
if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; thenecho "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script."# echo "$ANDROID_TOOLCHAIN"# exit 1
ficase $_ANDROID_ARCH inarch-arm)     ANDROID_TOOLS="arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld";;arch-x86)   ANDROID_TOOLS="i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld";;     *)echo "ERROR ERROR ERROR";;
esacfor tool in $ANDROID_TOOLS
do# Error checkingif [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; thenecho "Error: Failed to find $tool. Please edit this script."# echo "$ANDROID_TOOLCHAIN/$tool"# exit 1fi
done# Only modify/export PATH if ANDROID_TOOLCHAIN good
if [ ! -z "$ANDROID_TOOLCHAIN" ]; thenexport ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN"export PATH="$ANDROID_TOOLCHAIN":"$PATH"
fi###################################################################### For the Android SYSROOT. Can be used on the command line with --sysroot
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
export CROSS_SYSROOT="$ANDROID_SYSROOT"
export NDK_SYSROOT="$ANDROID_SYSROOT"# Error checking
if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; thenecho "Error: ANDROID_SYSROOT is not valid. Please edit this script."# echo "$ANDROID_SYSROOT"# exit 1
fi###################################################################### If the user did not specify the FIPS_SIG location, try and pick it up
# If the user specified a bad location, then try and pick it up too.
if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then# Try and locate it_FIPS_SIG=""if [ -d "/usr/local/ssl/$_ANDROID_API" ]; then_FIPS_SIG=`find "/usr/local/ssl/$_ANDROID_API" -name incore`fiif [ ! -e "$_FIPS_SIG" ]; then_FIPS_SIG=`find $PWD -name incore`fi# If a path was set, then export itif [ ! -z "$_FIPS_SIG" ] && [ -e "$_FIPS_SIG" ]; thenexport FIPS_SIG="$_FIPS_SIG"fi
fi# Error checking. Its OK to ignore this if you are *not* building for FIPS
if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; thenecho "Error: FIPS_SIG does not specify incore module. Please edit this script."# echo "$FIPS_SIG"# exit 1
fi###################################################################### Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored.
export MACHINE=armv7
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=armv7-a
export CROSS_COMPILE="arm-linux-androideabi-"#export AR=arm-linux-androideabi-ar
export AS=arm-linux-androideabi-as
#export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export LD=arm-linux-androideabi-ld
export NM=arm-linux-androideabi-nm
export RANLIB=arm-linux-androideabi-ranlib
export STRIP=arm-linux-androideabi-stripif [ "$_ANDROID_ARCH" == "arch-x86" ]; thenexport MACHINE=i686export RELEASE=2.6.37export SYSTEM=androidexport ARCH=x86export CROSS_COMPILE="i686-linux-android-"
fi# For the Android toolchain
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
export SYSROOT="$ANDROID_SYSROOT"
export NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_API="$_ANDROID_API"# CROSS_COMPILE and ANDROID_DEV are DFW (Don't Fiddle With). Its used by OpenSSL build system.
# export CROSS_COMPILE="arm-linux-androideabi-"
export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"
export HOSTCC=gccVERBOSE=1
if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; thenecho "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"echo "ANDROID_ARCH: $_ANDROID_ARCH"echo "ANDROID_EABI: $_ANDROID_EABI"echo "ANDROID_API: $ANDROID_API"echo "ANDROID_SYSROOT: $ANDROID_SYSROOT"echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN"echo "FIPS_SIG: $FIPS_SIG"echo "CROSS_COMPILE: $CROSS_COMPILE"echo "ANDROID_DEV: $ANDROID_DEV"echo "ARCH: $ARCH"echo "AR: $AR"echo "AS: $AS"echo "CC: $CC"echo "CXX: CXX"echo "LD: $LD"echo "NM: $NM"echo "RANLIB: $RANLIB"echo "STRIP: $STRIP"
fi

如果是在Windows环境下编辑,在Linux环境下执行时会报错不能识别的命令,这是因为Windows换行是\r\n,Linux是\r,需要转换一下:

wangning@SZX1000291132:/home/clouddragon/packages/tmp> sed -i 's/\r$//' setenv-android_64.sh
wangning@SZX1000291132:/home/clouddragon/packages/tmp> sed -i 's/\r$//' setenv-android_32.sh

4 设置环境变量并配置openssl

官方给出的命令:

$ perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
$ ./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=/usr/local/ssl/android-14/

因为我的openssl-OpenSSL_1_1_0g 目录没有Makefile.org,这里用makefile.shared代替

wangning@SZX1000291132:/home/clouddragon/packages/tmp/openssl-OpenSSL_1_1_0g> ls
ACKNOWLEDGEMENTS  demos             libssl.pc        os-dep
apps              doc               libssl.so        README
appveyor.yml      engines           libssl.so.1.1    README.ECC
AUTHORS           e_os.h            LICENSE          README.ENGINE
build.info        external          Makefile         README.FIPS
CHANGES           FAQ               Makefile.shared  ssl
config            fuzz              ms               ssl.map
config.com        include           NEWS             test
configdata.pm     INSTALL           NOTES.DJGPP      tools
Configurations    libcrypto.a       NOTES.PERL       util
Configure         libcrypto.pc      NOTES.UNIX       VMS
CONTRIBUTING      libcrypto.so      NOTES.VMS
crypto            libcrypto.so.1.1  NOTES.WIN
crypto.map        libssl.a          openssl.pc

这样可以配置成功。但是我要用自己的工具链既要编译32位又要编译64位,所以我写成了脚本。

64位setenv-android_64.sh:

#~ #!/bin/bash
# set env variables
#source setenv-android.sh
export TOOLCHAIN=/home/clouddragon/packages/tmp/toolchain-arm
export NDK_ROOT=/home/clouddragon/packages/tmp/android-ndk-r16b# configure toolchain
export SYSROOT=$TOOLCHAIN/sysroot
export PATH=$PATH:$TOOLCHAIN/bin:$SYSROOT/usr/local/bin#export AR=aarch64-linux-android-ar
export AS=aarch64-linux-android-as
#export CC=aarch64-linux-android-gcc
export CXX=aarch64-linux-android-g++
export LD=aarch64-linux-android-ld
export NM=aarch64-linux-android-nm
export RANLIB=aarch64-linux-android-ranlib
export STRIP=aarch64-linux-android-stripexport ANDROID_NDK_ROOT=$NDK_ROOT
. $NDK_ROOT/build/tools/ndk-common.shexport ARCH=aarch64
export CPPFLAGS="-MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes   -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Wa,--noexecstack -Wformat -Werror=format-security -DANDROID -fvisibility=hidden"# configure toolchain
# Perl is optional, and may fail in OpenSSL 1.1.0
cd openssl-OpenSSL_1_1_0g && \
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.shared./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine#
make depend#
make clean make all 

32位setenv-android_32.sh:

#~ #!/bin/bash
# set env variables
#source setenv-android.sh
export TOOLCHAIN=/home/clouddragon/packages/tmp/toolchain-arm32
export NDK_ROOT=/home/clouddragon/packages/tmp/android-ndk-r16b# configure toolchain
export SYSROOT=$TOOLCHAIN/sysroot
export PATH=$PATH:$TOOLCHAIN/bin:$SYSROOT/usr/local/bin#export AR=arm-linux-androideabi-ar
export AS=arm-linux-androideabi-as
#export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export LD=arm-linux-androideabi-ld
export NM=arm-linux-androideabi-nm
export RANLIB=arm-linux-androideabi-ranlib
export STRIP=arm-linux-androideabi-stripexport ANDROID_NDK_ROOT=$NDK_ROOT
. $NDK_ROOT/build/tools/ndk-common.shexport ARCH=armv7-a
export CPPFLAGS="-MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes   -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Wa,--noexecstack -Wformat -Werror=format-security -DANDROID -fvisibility=hidden"# configure toolchain
# Perl is optional, and may fail in OpenSSL 1.1.0
cd openssl-OpenSSL_1_1_0g && \
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.shared./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine#
make depend#
make clean make all 

5 编译

编译32位:

wangning@SZX1000291132:/home/clouddragon/packages/tmp> ./setenv-android_32.sh
wangning@SZX1000291132:/home/clouddragon/packages/tmp> ./build_openssl_1.1.0g_32.sh

编译64位:

wangning@SZX1000291132:/home/clouddragon/packages/tmp> ./setenv-android_64.sh
wangning@SZX1000291132:/home/clouddragon/packages/tmp> ./build_openssl_1.1.0g_64.sh

最终会在openssl-OpenSSL_1_1_0g目录里生成libcrypto.a和libssl.a

Linux 下 Android NDK 编译 openssl相关推荐

  1. libuv编译Linux,OS X下 Android NDK 编译 libuv

    准备工作 1.安装 NDK 下载对应版本,并添加安装路径至环境变量 (我用的是NDK14 rb,貌似最新的NDK编译有问题) 2.下载libuv 源码,并解压,我下载的版本是v1.11.0 这里提一句 ...

  2. Android NDK编译中在libs\armeabi中加入第三方so库文件的方法

    Android NDK编译中在libs\armeabi中加入第三方so库文件的方法 假设要加入库文件的名字为libffmpeg.so文件 1.要在project\jni目录下新建一目录prebuilt ...

  3. android.mk ndk编译选项优化,Android NDK 编译脚本分析 之一

    版权信息:本文为本人原创,欢迎转载,但请著明出处,并保留本版权信息. Android NDK编译脚本编写起来还是是比较简单条理的,然而它的语法和传统的linux GNU Make编译脚本的编写似乎有很 ...

  4. Android NDK 编译 三方库记录 及 jni库封装问题

    因工作需求, 要将原先的c++库跨平台编译,在Android上运行, 其依赖了几个第三方库, 也需要一起编译, 在此做个记录 所需工具(centos 系统上完成) 1. cmake 3.15.6 2. ...

  5. Windows下用ndk编译ffmpeg

    Windows下用ndk编译ffmpeg   第一步:创建一个android工程,然后将ffmpeg整体放到jni下,并创建Android.mk和Application.mk Android.mk: ...

  6. android jni不适用ndk,Android NDK编译之undefined reference to 'JNI_CreateJavaVM'

    利用Android NDK编译动态库,在C文件中调用了两个JNI函数:JNI_GetDefaultJavaVMInitArgs和JNI_CreateJavaVM.编译的时候始终报以下错误: XXX: ...

  7. android arm代码,为Android ARMV7编译OpenSSL 1.1.0

    我试图在Ubuntu机器上为Android ARMV7编译OpenSSL 1.1.0(k).但我只能为android,android armabi,android64(-aarch64)目标编译. 我 ...

  8. Python 3.10版本及其依赖项 Linux下源码编译 安装到指定路径/目录

    Python 3.10版本及其依赖项 Linux下源码编译 安装到指定路径/目录 安装需求 准备工作 Python及其依赖项 libffi glibc GDBM mpdecimal bz2 xz re ...

  9. Android NDK 编译PjSip 2.6 之 搭建PjSip apk开发环境 (三)

    Android NDK 编译PjSip 2.6 之 PjSip编译 (二)中已经把so 和java文件编译出来.可以开始搭建apk的开发环境. 我们导入PjSip的example apk程序,编译生成 ...

  10. linux下源码编译升级ssh版本,ssh打补丁过程

    linux下源码编译升级ssh版本过程 记录打补丁之ssh源码编译升级过程 安装前软件准备 升级步骤 结尾及一些坑 记录打补丁之ssh源码编译升级过程 应安全报告要求需要修复操作系统中的ssh协议,原 ...

最新文章

  1. 使用AppCompat项目模版
  2. HDU 4121 Xiangqi --模拟
  3. 解决eclipse中出现Resource is out of sync with the file system问题
  4. MySQL深度剖析之Buffer Pool专题(2021)
  5. 计算机科学与技术做什么实验,计算机科学与技术专业实验教学大纲
  6. 关于vc++6.0“打开文件“功能问题的解决方法
  7. springMVC配置
  8. 【车辆识别】基于matlab GUI小波和盒维数车型识别【含Matlab源码 727期】
  9. 谷歌FLASH无法添加保存网站
  10. 使用技巧-输出彩色TIF格式分类结果
  11. Excel如何取消合并单元格并填充空单元格
  12. RHEL8.x-RedHat-Podman
  13. python面试自我介绍怎么介绍比较好_面试的时候,如何自我介绍?
  14. 为自动驾驶carla配置车流量
  15. 计算机应用领域的实践,计算机技术在通信技术领域的应用实践探微
  16. python推荐算法课程_Python数据科学:全栈技术详解4-推荐算法
  17. 服务器2008系统备份检测不到u盘,U盘不能识别简单维修一例
  18. PTA 6-3 舞伴问题 (20 分) C语言
  19. 为数据安全而生,阿里云容灾备份方案场景实践解析
  20. 了解运营的本质,内容运营,用户运营,活动运营,产品运营。。。

热门文章

  1. Ubuntu18.04运行QQ音乐
  2. PYTHON学习创建当先时间和昨天时间
  3. 网银支付接口编程资料汇总
  4. 风花雪月·《基层风云·1》·四
  5. 关于C51中“大小端存储”问题的详解
  6. Advanced Algorithm 听课笔记(Useful Inequalities Balls and Bins)
  7. BufferedImage 图片背景色黑色问题
  8. 如何用东华大学的邮箱来在Cousera进行学生认证
  9. 【转帖】M1、M2增速
  10. 如何使用计算机管理员账户密码是什么意思,电脑管理员密码是什么