二、NDK交叉编译openssl

1、创建开源模块根目录

mkdir AndroidWorkSpace/OpenSourceModule

2、openssl源码

获取openssl:https://www.openssl.org/source/

我做这个的时候最新的是1.1.1e
openssl-1.1.1e.tar.gz

进入开源模块目录:
cd OpenSourceModule
解压到当前目录:
tar vzxf openssl-1.1.1e.tar.gz
 

3、编译

进入openssl根目录:cd openssl-1.1.1e
-D__ANDROID_API__目前理解是使用哪个版本api编译,也就是支持的最低api版本,因为android向下兼容。
执行脚本build-android.sh

#!/bin/bash
set -e
set -x
#
# Copyright 2016 leenjewel
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

MY_OPENSSL_PATH=/home/renz/android/AndroidWorkSpace/OpenSourceModule
func_cmp(){
	make clean &&
	rm -rf $MY_OPENSSL_PATH/OpensslDir/$ARCH &&
	mkdir -p $MY_OPENSSL_PATH/OpensslDir/$ARCH &&
	export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH &&
	./Configure $ARCH_NAME -D__ANDROID_API__=23 --prefix=$MY_OPENSSL_PATH/OpensslDir/$ARCH &&
	make && make install
}


CC=clang
ARCH_NAME=android-arm
export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH &&
#先生成make一次,为了make clean能够执行
./Configure $ARCH_NAME -D__ANDROID_API__=23 --prefix=$MY_OPENSSL_PATH/OpensslDir/$ARCH

 #for ARCH in armeabi-v7a armeabi arm64-v8a x86 x86_64 mips mips64
for ARCH in armeabi-v7a armeabi arm64-v8a x86 x86_64
do
	echo $ARCH
	if [ "$ARCH" = "armeabi-v7a" ]; then
		ARCH_NAME=android-arm
	fi
	if [ "$ARCH" = "armeabi" ]; then
		ARCH_NAME=android-arm
	fi
	if [ "$ARCH" = "arm64-v8a" ]; then
		ARCH_NAME=android-arm64
	fi
	if [ "$ARCH" = "mips" ]; then
		ARCH_NAME=android-mips
	fi
	if [ "$ARCH" = "mips64" ]; then
		ARCH_NAME=android-mips64
	fi
	if [ "$ARCH" = "x86" ]; then
		ARCH_NAME=android-x86
	fi
	if [ "$ARCH" = "x86_64" ]; then
		ARCH_NAME=android-x86_64
	fi
	echo $TOOL_CHAIN
	func_cmp
done

脚本需要根据自己的路径修改MY_OPENSSL_PATH变量
脚本其中使用的是clang编译,如果想了解详细过程,请参考博客
使用clang编译openssl1.1.1d
https://blog.csdn.net/u011077027/article/details/102713175

编译完成会出现arm64-v8a  armeabi  armeabi-v7a  x86  x86_64文件夹

参考博文

Android下openssl编译和使用(一)
https://blog.csdn.net/zoujin6649/article/details/89891720
Android下openssl编译和使用(二)(验证ok,但是需要修改)
https://blog.csdn.net/zoujin6649/article/details/89949176
使用clang编译openssl1.1.1d
https://blog.csdn.net/u011077027/article/details/102713175
Ubuntu16.04升级cmake到3.11.3
https://www.wandouip.com/t5i137471/

 

©️2020 CSDN 皮肤主题: 点我我会动 设计师:上身试试 返回首页