Support OpenSSL shared library build in Android example.
This commit is contained in:
parent
4d9baf6fc0
commit
872d8ebd3b
@ -9,8 +9,9 @@ COPY ./check-environment.sh ./fetch-sdk.sh ./
|
||||
RUN ./fetch-sdk.sh SDK "$ANDROID_NDK_VERSION"
|
||||
|
||||
ARG OPENSSL_VERSION=OpenSSL_1_1_1w
|
||||
ARG BUILD_SHARED_OPENSSL_LIBS=
|
||||
COPY ./build-openssl.sh ./
|
||||
RUN ./build-openssl.sh SDK "$ANDROID_NDK_VERSION" openssl "$OPENSSL_VERSION"
|
||||
RUN ./build-openssl.sh SDK "$ANDROID_NDK_VERSION" openssl "$OPENSSL_VERSION" "$BUILD_SHARED_OPENSSL_LIBS"
|
||||
|
||||
ADD "https://api.github.com/repos/tdlib/td/git/refs/heads/master" version.json
|
||||
ARG COMMIT_HASH=master
|
||||
|
@ -27,4 +27,4 @@ You can also build TDLib with [JSON interface](https://github.com/tdlib/td#using
|
||||
|
||||
You can pass an empty string instead of any script parameter to use its default value. For example, you can use the command `./build-tdlib.sh '' '' '' '' 'JSON'` to build TDLib with [JSON interface](https://github.com/tdlib/td#using-json) using default values for other parameters.
|
||||
|
||||
Alternatively, you can use Docker to build TDLib for Android. Use `docker build --output tdlib .` to build the latest TDLib commit from Github, or `docker build --build-arg COMMIT_HASH=<commit-hash> --output tdlib .` to build specific commit. The output archives will be placed in the directory "tdlib" as specified. Additionally, you can specify build arguments "TDLIB_INTERFACE", "ANDROID_NDK_VERSION", "OPENSSL_VERSION", and "ANDROID_STL" to the provided Dockerfile. For example, use `docker build --build-arg TDLIB_INTERFACE=JSON --output tdlib .` to build the latest TDLib with JSON interface.
|
||||
Alternatively, you can use Docker to build TDLib for Android. Use `docker build --output tdlib .` to build the latest TDLib commit from Github, or `docker build --build-arg COMMIT_HASH=<commit-hash> --output tdlib .` to build specific commit. The output archives will be placed in the directory "tdlib" as specified. Additionally, you can specify build arguments "TDLIB_INTERFACE", "ANDROID_NDK_VERSION", "OPENSSL_VERSION", "BUILD_SHARED_OPENSSL_LIBS", and "ANDROID_STL" to the provided Dockerfile. For example, use `docker build --build-arg TDLIB_INTERFACE=JSON --output tdlib .` to build the latest TDLib with JSON interface.
|
||||
|
@ -4,6 +4,7 @@ ANDROID_SDK_ROOT=${1:-SDK}
|
||||
ANDROID_NDK_VERSION=${2:-23.2.8568313}
|
||||
OPENSSL_INSTALL_DIR=${3:-third-party/openssl}
|
||||
OPENSSL_VERSION=${4:-OpenSSL_1_1_1w} # openssl-3.3.0
|
||||
BUILD_SHARED_LIBS=$5
|
||||
|
||||
if [ ! -d "$ANDROID_SDK_ROOT" ] ; then
|
||||
echo "Error: directory \"$ANDROID_SDK_ROOT\" doesn't exist. Run ./fetch-sdk.sh first, or provide a valid path to Android SDK."
|
||||
@ -17,6 +18,11 @@ fi
|
||||
|
||||
source ./check-environment.sh || exit 1
|
||||
|
||||
if [[ "$OS_NAME" == "win" ]] && [[ "$BUILD_SHARED_LIBS" ]] ; then
|
||||
echo "Error: OpenSSL shared libraries can't be built on Windows because of 'The command line is too long.' error during build. You can run the script in WSL instead."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p $OPENSSL_INSTALL_DIR || exit 1
|
||||
|
||||
ANDROID_SDK_ROOT="$(cd "$(dirname -- "$ANDROID_SDK_ROOT")" >/dev/null; pwd -P)/$(basename -- "$ANDROID_SDK_ROOT")"
|
||||
@ -32,7 +38,7 @@ tar xzf $OPENSSL_VERSION.tar.gz || exit 1
|
||||
rm $OPENSSL_VERSION.tar.gz || exit 1
|
||||
cd openssl-$OPENSSL_VERSION
|
||||
|
||||
export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION # for OpenSSL 3.0
|
||||
export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION # for OpenSSL 3.*.*
|
||||
export ANDROID_NDK_HOME=$ANDROID_NDK_ROOT # for OpenSSL 1.1.1
|
||||
PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/bin:$PATH
|
||||
|
||||
@ -53,15 +59,17 @@ if [[ ${ANDROID_NDK_VERSION%%.*} -ge 26 ]] ; then
|
||||
ANDROID_API32=21
|
||||
fi
|
||||
|
||||
SHARED_BUILD_OPTION=$([ "$BUILD_SHARED_LIBS" ] && echo "shared" || echo "no-shared")
|
||||
|
||||
for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
|
||||
if [[ $ABI == "x86" ]] ; then
|
||||
./Configure android-x86 no-shared -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API32 || exit 1
|
||||
./Configure android-x86 ${SHARED_BUILD_OPTION} -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API32 || exit 1
|
||||
elif [[ $ABI == "x86_64" ]] ; then
|
||||
./Configure android-x86_64 no-shared -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API64 || exit 1
|
||||
./Configure android-x86_64 ${SHARED_BUILD_OPTION} -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API64 || exit 1
|
||||
elif [[ $ABI == "armeabi-v7a" ]] ; then
|
||||
./Configure android-arm no-shared -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API32 -D__ARM_MAX_ARCH__=8 || exit 1
|
||||
./Configure android-arm ${SHARED_BUILD_OPTION} -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API32 -D__ARM_MAX_ARCH__=8 || exit 1
|
||||
elif [[ $ABI == "arm64-v8a" ]] ; then
|
||||
./Configure android-arm64 no-shared -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API64 || exit 1
|
||||
./Configure android-arm64 ${SHARED_BUILD_OPTION} -U__ANDROID_API__ -D__ANDROID_API__=$ANDROID_API64 || exit 1
|
||||
fi
|
||||
|
||||
sed -i.bak 's/-O3/-O3 -ffunction-sections -fdata-sections/g' Makefile || exit 1
|
||||
@ -70,7 +78,11 @@ for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
|
||||
make -j4 -s || exit 1
|
||||
|
||||
mkdir -p $OPENSSL_INSTALL_DIR/$ABI/lib/ || exit 1
|
||||
cp libcrypto.a libssl.a $OPENSSL_INSTALL_DIR/$ABI/lib/ || exit 1
|
||||
if [ "$BUILD_SHARED_LIBS" ] ; then
|
||||
cp libcrypto.so libssl.so $OPENSSL_INSTALL_DIR/$ABI/lib/ || exit 1
|
||||
else
|
||||
cp libcrypto.a libssl.a $OPENSSL_INSTALL_DIR/$ABI/lib/ || exit 1
|
||||
fi
|
||||
cp -r include $OPENSSL_INSTALL_DIR/$ABI/ || exit 1
|
||||
|
||||
make distclean || exit 1
|
||||
|
@ -100,6 +100,11 @@ for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
|
||||
cp "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/sysroot/usr/lib/$FULL_ABI/libc++_shared.so" tdlib/libs/$ABI/ || exit 1
|
||||
"$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/bin/llvm-strip" tdlib/libs/$ABI/libc++_shared.so || exit 1
|
||||
fi
|
||||
if [ -e "$OPENSSL_INSTALL_DIR/$ABI/lib/libcrypto.so" ] ; then
|
||||
cp "$OPENSSL_INSTALL_DIR/$ABI/lib/libcrypto.so" "$OPENSSL_INSTALL_DIR/$ABI/lib/libssl.so" tdlib/libs/$ABI/ || exit 1
|
||||
"$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/bin/llvm-strip" tdlib/libs/$ABI/libcrypto.so || exit 1
|
||||
"$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/bin/llvm-strip" tdlib/libs/$ABI/libssl.so || exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Compressing..."
|
||||
|
Loading…
Reference in New Issue
Block a user