项目中需要用到openssl库的AES加密,写下来方便以后查阅。

编译

1、安装Linux版本的NDK

编译openssl需要使用NDK,先下载NDK:

# 在home目录下建立ndk目录
$ mkdir android
$ cd android
$ wget https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip
$ unzip android-ndk-r14b-linux-x86_64.zip

最后NDK被解压在:/home/zoujin6649/android/android-ndk-r14b

2、下载openssl源码

# 下载openssl源码
$ cd android
$ wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1a.tar.gz
$ tar -zxvf openssl-1.1.1a.tar.gz

3、开始编译

根据NOTES.ANDROID文件提示的执行以下命令设置环境变量并安装

$ cd /home/zoujin6649/android/openssl-1.1.1b
$ rm -rf ./output
$ mkdir ./output

$ export ANDROID_NDK=/home/zoujin6649/android/android-ndk-r14b
$ export PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
$ ./Configure android-arm -D__ANDROID_API__=23 --prefix=/home/zoujin6649/android/openssl-1.1.1b/output

$ make && make install

4、编译其他cpu架构的库

# armeabi armeabi-v7a armeabi-v7a-hard arm64-v8a mips mips64 x86 x86_64
$ export ARCH=armeabi

$ cd /home/zoujin6649/android/openssl-1.1.1b
$ rm -rf ./output-$ARCH
$ mkdir ./output-$ARCH

$ export ANDROID_NDK=/home/zoujin6649/android/android-ndk-r14b
$ export PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
$ ./Configure android-arm -D__ANDROID_API__=23 --prefix=/home/zoujin6649/android/openssl-1.1.1b/output-$ARCH

$ make && make install

5、编译脚本编译各cpu架构的库

编写脚本build-android.sh如下:

func_cmp(){
	cd /home/zoujin6649/android/openssl-1.1.1b
	make clean
	rm -rf ./output-$ARCH
	mkdir ./output-$ARCH
	export ANDROID_NDK=/home/zoujin6649/android/android-ndk-r14b
	export PATH=$ANDROID_NDK/toolchains/$TOOL_CHAIN/prebuilt/linux-x86_64/bin:$PATH
	./Configure android-$ARCH_NAME -D__ANDROID_API__=23 --prefix=/home/zoujin6649/android/openssl-1.1.1b/output-$ARCH
	make && make install
}

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

执行编译

$ cd /home/zoujin6649/android/openssl-1.1.1b
$ sh build-android.sh

 

GitHub 加速计划 / ope / openssl
25.13 K
9.99 K
下载
传输层安全性/安全套接层及其加密库
最近提交(Master分支:1 个月前 )
fd39d1c8 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/25095) 3 个月前
ae87c488 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/25095) 3 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐