MAC下OpenSSL Android库编译配置

1.准备

OpenSSL 源码可以直接去官网下载

make

2.参照文章

https://wiki.openssl.org/index.php/Android

https://segmentfault.com/a/1190000005747285

3.直接运行
chmod a+x build-openssl-android.sh
./build-openssl-android.sh

在openssl-1.0.2g目录下找到libcrypto.a libssl.a
或者/usr/local/ssl/android-21 去找
build-openssl-android.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

#####################################################################

# Set 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 NDK_ROOT is not specified, the script will

# try to pick it up with the value of _NDK_ROOT below. If

# NDK_ROOT is set, then the value is ignored.

# _ANDROID_NDK="android-ndk-r8e"

_ANDROID_NDK="android-ndk-r10e"

# _ANDROID_NDK="android-ndk-r10"

# Set _ANDROID_EABI to the EABI you want to use. You can find the

# list in $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-18"

# _ANDROID_API="android-19"

#####################################################################

# If the user did not specify the NDK location, try and pick it up.

# We expect something like NDK_ROOT=/opt/android-ndk-r8e

# or NDK_ROOT=/usr/local/android-ndk-r8e.

if [ -z "$NDK_ROOT" ]; then

_NDK_ROOT=""

if [ -z "$_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then

_NDK_ROOT="/usr/local/$_ANDROID_NDK"

fi

if [ -z "$_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then

_NDK_ROOT="/opt/$_ANDROID_NDK"

fi

if [ -z "$_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then

_NDK_ROOT="$HOME/$_ANDROID_NDK"

fi

if [ -z "$_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then

_NDK_ROOT="$PWD/$_ANDROID_NDK"

fi

# If a path was set, then export it

if [ ! -z "$_NDK_ROOT" ] && [ -d "$_NDK_ROOT" ]; then

export NDK_ROOT="$_NDK_ROOT"

fi

fi

# Error checking

# 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 "$NDK_ROOT" ] || [ ! -d "$NDK_ROOT" ]; then

echo "Error: NDK_ROOT is not a valid path. Please edit this script."

# echo "$NDK_ROOT"

# exit 1

fi

# Error checking

if [ ! -d "$NDK_ROOT/toolchains" ]; then

echo "Error: NDK_ROOT/toolchains is not a valid path. Please edit this script."

# echo "$NDK_ROOT/toolchains"

# exit 1

fi

# Error checking

if [ ! -d "$NDK_ROOT/toolchains/$_ANDROID_EABI" ]; then

echo "Error: ANDROID_EABI is not a valid path. Please edit this script."

# echo "$NDK_ROOT/toolchains/$_ANDROID_EABI"

# exit 1

fi

#####################################################################

# Based on 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.html

ANDROID_TOOLCHAIN=""

for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"

do

if [ -d "$NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; then

ANDROID_TOOLCHAIN="$NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin"

break

fi

done

# Error checking

if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then

echo "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script."

# echo "$ANDROID_TOOLCHAIN"

# exit 1

fi

case $_ANDROID_ARCH in

arch-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"

;;

esac

for tool in $ANDROID_TOOLS

do

# Error checking

if [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; then

echo "Error: Failed to find $tool. Please edit this script."

# echo "$ANDROID_TOOLCHAIN/$tool"

# exit 1

fi

done

# Only modify/export PATH if ANDROID_TOOLCHAIN good

if [ ! -z "$ANDROID_TOOLCHAIN" ]; then

export 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="$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" ]; then

echo "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`

fi

if [ ! -e "$_FIPS_SIG" ]; then

_FIPS_SIG=`find $PWD -name incore`

fi

# If a path was set, then export it

if [ ! -z "$_FIPS_SIG" ] && [ -e "$_FIPS_SIG" ]; then

export 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" ]; then

echo "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=arm

export CROSS_COMPILE="arm-linux-androideabi-"

if [ "$_ANDROID_ARCH" == "arch-x86" ]; then

export MACHINE=i686

export RELEASE=2.6.37

export SYSTEM=android

export ARCH=x86

export 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="$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="$NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"

export HOSTCC=gcc

VERBOSE=1

if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then

echo "NDK_ROOT: $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"

fi

cd openssl-1.0.2g

make clean

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_API

make depend

make all

sudo -E make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib

需要注意ndk环境变量配置;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,376评论 6 491
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,126评论 2 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,966评论 0 347
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,432评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,519评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,792评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,933评论 3 406
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,701评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,143评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,488评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,626评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,292评论 4 329
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,896评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,742评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,977评论 1 265
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,324评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,494评论 2 348

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 171,761评论 25 707
  • OpenSSL是一个强大的开源安全套接字层密码库,它包含了主要的密码学算法,常用的密钥和证书封装管理以及SSL协议...
    姜家志阅读 14,880评论 13 23
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,410评论 2 45
  • 郭相麟 这是个 他们说的网络时代 世界是平的 也是宽的、厚的、 还是窄的、尖锐的 带着不经意的评价 口水淹过了 ...
    郭相麟阅读 138评论 0 0
  • 1、今天总结回顾了一下上两个月,主要是4月做的事,突然发现日子一天天过着,竟也收获了很多东西,亲情、工作,爱情,自...
    活跃在兔子毛顶端阅读 164评论 0 0