Created
May 17, 2024 15:18
-
-
Save GNUGradyn/50ed6a4b09fc744097fcef6140f4e826 to your computer and use it in GitHub Desktop.
Build openSSL 1.1.1u for android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Variables | |
OPENSSL_VERSION="openssl-1.1.1u" | |
NDK_VERSION="android-ndk-r26d" | |
ANDROID_API="21" | |
ANDROID_ARCHS=("arm" "arm64" "x86" "x86_64") | |
# Create and navigate to the working directory | |
mkdir -p openssl | |
cd openssl | |
# Download OpenSSL | |
if [ ! -f ${OPENSSL_VERSION}.tar.gz ]; then | |
wget https://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz | |
fi | |
tar -xf ${OPENSSL_VERSION}.tar.gz | |
# Download and unzip Android NDK | |
if [ ! -d ${NDK_VERSION} ]; then | |
wget https://dl.google.com/android/repository/${NDK_VERSION}-linux.zip | |
unzip ${NDK_VERSION}-linux.zip | |
fi | |
# Set NDK path | |
export ANDROID_NDK_HOME=$(pwd)/${NDK_VERSION} | |
export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH | |
# Navigate to the OpenSSL directory | |
cd ${OPENSSL_VERSION} | |
# Create output directory structure | |
OUTPUT_DIR="../openssl-build" | |
mkdir -p ${OUTPUT_DIR}/include/openssl | |
# Build OpenSSL for each specified architecture | |
for ARCH in "${ANDROID_ARCHS[@]}"; do | |
case $ARCH in | |
arm) | |
TARGET="android-arm" | |
ARCH_DIR="armeabi-v7a" | |
;; | |
arm64) | |
TARGET="android-arm64" | |
ARCH_DIR="arm64-v8a" | |
;; | |
x86) | |
TARGET="android-x86" | |
ARCH_DIR="x86" | |
;; | |
x86_64) | |
TARGET="android-x86_64" | |
ARCH_DIR="x86_64" | |
;; | |
*) | |
echo "Unknown architecture: $ARCH" | |
exit 1 | |
;; | |
esac | |
echo "Building OpenSSL for ${ARCH}..." | |
# Configure and build | |
./Configure $TARGET -D__ANDROID_API__=${ANDROID_API} | |
make -j$(nproc) | |
# Install the built OpenSSL libraries and includes | |
ARCH_OUTPUT_DIR="${OUTPUT_DIR}/libs/${ARCH_DIR}" | |
mkdir -p ${ARCH_OUTPUT_DIR} | |
cp libcrypto.a libssl.a ${ARCH_OUTPUT_DIR} | |
# Copy headers only once | |
if [ ! "$(ls -A ${OUTPUT_DIR}/include/openssl)" ]; then | |
cp -r include/openssl/* ${OUTPUT_DIR}/include/openssl/ | |
fi | |
# Clean up for the next build | |
make clean | |
done | |
echo "OpenSSL build completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment