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/