二、NDKクロスコンパイルopenssl

3087 ワード

1、オープンソースモジュールルートディレクトリの作成
mkdir AndroidWorkSpace/OpenSourceModule
2、opensslソース
Opensslを取得するには:https://www.openssl.org/source/
私がこれを作ったときの最新は1.1.1 e openssl-1.1.1 eです.tar.gz
オープンソースモジュールディレクトリに入る:cd OpenSourceModule現在のディレクトリに解凍:tar vzxf openssl-1.1.1 e.tar.gz  
3、コンパイル
Opensslルートディレクトリへ:cd openssl-1.1.1 e-D_ANDROID_API__現在、androidが下向きに互換性があるため、どのバージョンのapiコンパイルを使用するか、つまりサポートされている最低apiバージョンが理解されています.スクリプトの実行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コンパイルopenssl 1を使用してください.1.1d https://blog.csdn.net/u011077027/article/details/102713175
コンパイルが完了するとarm 64-v 8 a armeabi armeabi-v 7 a x 86 x 86_が表示されます.64フォルダ
参考博文
Android下opensslコンパイルと使用(一)https://blog.csdn.net/zoujin6649/article/details/89891720Android下opensslコンパイルと使用(二)(検証ok、ただし修正が必要)https://blog.csdn.net/zoujin6649/article/details/89949176clangを使用してopenssl 1をコンパイルします.1.1d https://blog.csdn.net/u011077027/article/details/102713175 Ubuntu16.04 cmakeを3.11.3にアップグレードhttps://www.wandouip.com/t5i137471/