Allow to specify custom path for prebuilt Android OpenSSL.

This commit is contained in:
levlam 2022-08-13 10:31:41 +03:00
parent bb6bd4244f
commit d1a6595c20
4 changed files with 25 additions and 21 deletions

View File

@ -13,7 +13,7 @@ if (CMAKE_CROSSCOMPILING)
td_set_up_compiler() td_set_up_compiler()
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -flto=thin -Oz") string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -flto=thin -Oz")
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/openssl/${ANDROID_ARCH_NAME}") list(APPEND CMAKE_FIND_ROOT_PATH "${OPENSSL_ROOT_DIR}")
add_subdirectory(${TD_DIR} td) add_subdirectory(${TD_DIR} td)
add_library(tdjni SHARED "${TD_DIR}/example/java/td_jni.cpp") add_library(tdjni SHARED "${TD_DIR}/example/java/td_jni.cpp")

View File

@ -13,8 +13,10 @@ You need a Bash shell on Linux, macOS, or Windows with some common tools, a C++
If you already have installed Android SDK and NDK, you can skip the second step and specify existing Android SDK root path and Android NDK version as the first and the second parameters to the subsequent scripts. Make sure that the SDK includes android-33 platform. If you already have installed Android SDK and NDK, you can skip the second step and specify existing Android SDK root path and Android NDK version as the first and the second parameters to the subsequent scripts. Make sure that the SDK includes android-33 platform.
If you already have prebuilt OpenSSL, you can skip the third step and specify path to the prebuild OpenSSL as the third parameter to the script `./build-tdlib.sh`.
If you want to update TDLib to a newer version, you need to run only the script `./build-tdlib.sh`. If you want to update TDLib to a newer version, you need to run only the script `./build-tdlib.sh`.
You can specify different OpenSSL version as the third parameter to the script `./build-openssl.sh`. By default OpenSSL 1.1.1 is used because of much smaller binary footprint than newer OpenSSL versions. You can specify different OpenSSL version as the fourth parameter to the script `./build-openssl.sh`. By default OpenSSL 1.1.1 is used because of much smaller binary footprint than newer OpenSSL versions.
You can build TDLib against shared standard C++ library by specifying "c++_shared" as the third parameter to the script `./build-tdlib.sh`. This can reduce total app size if you have a lot of other C++ code and want it to use the same shared library. You can build TDLib against shared standard C++ library by specifying "c++_shared" as the fourth parameter to the script `./build-tdlib.sh`. This can reduce total application size if you have a lot of other C++ code and want it to use the same shared library.

View File

@ -3,14 +3,14 @@ cd $(dirname $0)
ANDROID_SDK_ROOT=${1:-SDK} ANDROID_SDK_ROOT=${1:-SDK}
ANDROID_NDK_VERSION=${2:-23.2.8568313} ANDROID_NDK_VERSION=${2:-23.2.8568313}
OPENSSL_VERSION=${3:-OpenSSL_1_1_1q} # openssl-3.0.5 OPENSSL_INSTALL_DIR=${3:-third-party/openssl}
OPENSSL_VERSION=${4:-OpenSSL_1_1_1q} # openssl-3.0.5
if [ ! -d "$ANDROID_SDK_ROOT" ] ; then 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." echo "Error: directory \"$ANDROID_SDK_ROOT\" doesn't exist. Run ./fetch-sdk.sh first, or provide a valid path to Android SDK."
exit 1 exit 1
fi fi
OPENSSL_INSTALL_DIR="third-party/openssl"
if [ -d "$OPENSSL_INSTALL_DIR" ] ; then if [ -d "$OPENSSL_INSTALL_DIR" ] ; then
echo "Error: directory \"$OPENSSL_INSTALL_DIR\" already exists. Delete it manually to proceed." echo "Error: directory \"$OPENSSL_INSTALL_DIR\" already exists. Delete it manually to proceed."
exit 1 exit 1
@ -19,11 +19,11 @@ fi
source ./check-environment.sh || exit 1 source ./check-environment.sh || exit 1
ANDROID_SDK_ROOT="$(cd "$(dirname -- "$ANDROID_SDK_ROOT")" >/dev/null; pwd -P)/$(basename -- "$ANDROID_SDK_ROOT")" ANDROID_SDK_ROOT="$(cd "$(dirname -- "$ANDROID_SDK_ROOT")" >/dev/null; pwd -P)/$(basename -- "$ANDROID_SDK_ROOT")"
OPENSSL_INSTALL_DIR="$(cd "$(dirname -- "$OPENSSL_INSTALL_DIR")" >/dev/null; pwd -P)/$(basename -- "$OPENSSL_INSTALL_DIR")"
if [ ! -f $OPENSSL_VERSION.tar.gz ] ; then echo "Downloading OpenSSL sources..."
echo "Downloading OpenSSL sources..." rm -f $OPENSSL_VERSION.tar.gz || exit 1
$WGET https://github.com/openssl/openssl/archive/refs/tags/$OPENSSL_VERSION.tar.gz || exit 1 $WGET https://github.com/openssl/openssl/archive/refs/tags/$OPENSSL_VERSION.tar.gz || exit 1
fi
rm -rf ./openssl-$OPENSSL_VERSION || exit 1 rm -rf ./openssl-$OPENSSL_VERSION || exit 1
tar xzf $OPENSSL_VERSION.tar.gz || exit 1 tar xzf $OPENSSL_VERSION.tar.gz || exit 1
rm $OPENSSL_VERSION.tar.gz || exit 1 rm $OPENSSL_VERSION.tar.gz || exit 1
@ -41,14 +41,14 @@ if ! clang --help >/dev/null 2>&1 ; then
exit 1 exit 1
fi fi
for ARCH in arm64 arm x86_64 x86 ; do for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
if [[ $ARCH == "x86" ]]; then if [[ $ABI == "x86" ]]; then
./Configure android-x86 no-shared -U__ANDROID_API__ -D__ANDROID_API__=16 || exit 1 ./Configure android-x86 no-shared -U__ANDROID_API__ -D__ANDROID_API__=16 || exit 1
elif [[ $ARCH == "x86_64" ]]; then elif [[ $ABI == "x86_64" ]]; then
./Configure android-x86_64 no-shared -U__ANDROID_API__ -D__ANDROID_API__=21 || exit 1 ./Configure android-x86_64 no-shared -U__ANDROID_API__ -D__ANDROID_API__=21 || exit 1
elif [[ $ARCH == "arm" ]]; then elif [[ $ABI == "armeabi-v7a" ]]; then
./Configure android-arm no-shared -U__ANDROID_API__ -D__ANDROID_API__=16 -D__ARM_MAX_ARCH__=8 || exit 1 ./Configure android-arm no-shared -U__ANDROID_API__ -D__ANDROID_API__=16 -D__ARM_MAX_ARCH__=8 || exit 1
elif [[ $ARCH == "arm64" ]]; then elif [[ $ABI == "arm64-v8a" ]]; then
./Configure android-arm64 no-shared -U__ANDROID_API__ -D__ANDROID_API__=21 || exit 1 ./Configure android-arm64 no-shared -U__ANDROID_API__ -D__ANDROID_API__=21 || exit 1
fi fi
@ -57,10 +57,9 @@ for ARCH in arm64 arm x86_64 x86 ; do
make depend -s || exit 1 make depend -s || exit 1
make -j4 -s || exit 1 make -j4 -s || exit 1
rm -rf ../$OPENSSL_INSTALL_DIR/$ARCH/* || exit 1 mkdir -p $OPENSSL_INSTALL_DIR/$ABI/lib/ || exit 1
mkdir -p ../$OPENSSL_INSTALL_DIR/$ARCH/lib/ || exit 1 cp libcrypto.a libssl.a $OPENSSL_INSTALL_DIR/$ABI/lib/ || exit 1
cp libcrypto.a libssl.a ../$OPENSSL_INSTALL_DIR/$ARCH/lib/ || exit 1 cp -r include $OPENSSL_INSTALL_DIR/$ABI/ || exit 1
cp -r include ../$OPENSSL_INSTALL_DIR/$ARCH/ || exit 1
make distclean || exit 1 make distclean || exit 1
done done

View File

@ -3,7 +3,8 @@ cd $(dirname $0)
ANDROID_SDK_ROOT=${1:-SDK} ANDROID_SDK_ROOT=${1:-SDK}
ANDROID_NDK_VERSION=${2:-23.2.8568313} ANDROID_NDK_VERSION=${2:-23.2.8568313}
ANDROID_STL=${3:-c++_static} OPENSSL_INSTALL_DIR=${3:-third-party/openssl}
ANDROID_STL=${4:-c++_static}
if [ "$ANDROID_STL" != "c++_static" ] && [ "$ANDROID_STL" != "c++_shared" ] ; then if [ "$ANDROID_STL" != "c++_static" ] && [ "$ANDROID_STL" != "c++_shared" ] ; then
echo 'Error: ANDROID_STL must be either "c++_static" or "c++_shared".' echo 'Error: ANDROID_STL must be either "c++_static" or "c++_shared".'
@ -17,13 +18,13 @@ if [ ! -d "$ANDROID_SDK_ROOT" ] ; then
exit 1 exit 1
fi fi
OPENSSL_INSTALL_DIR="third-party/openssl"
if [ ! -d "$OPENSSL_INSTALL_DIR" ] ; then if [ ! -d "$OPENSSL_INSTALL_DIR" ] ; then
echo "Error: directory \"$OPENSSL_INSTALL_DIR\" doesn't exists. Run ./build-openssl.sh first." echo "Error: directory \"$OPENSSL_INSTALL_DIR\" doesn't exists. Run ./build-openssl.sh first."
exit 1 exit 1
fi fi
echo "Downloading annotation Java package..." echo "Downloading annotation Java package..."
rm -f android.jar annotation-1.4.0.jar || exit 1
$WGET https://maven.google.com/androidx/annotation/annotation/1.4.0/annotation-1.4.0.jar || exit 1 $WGET https://maven.google.com/androidx/annotation/annotation/1.4.0/annotation-1.4.0.jar || exit 1
echo "Generating TDLib source files..." echo "Generating TDLib source files..."
@ -44,6 +45,7 @@ rm -rf org || exit 1
ANDROID_SDK_ROOT="$(cd "$(dirname -- "$ANDROID_SDK_ROOT")" >/dev/null; pwd -P)/$(basename -- "$ANDROID_SDK_ROOT")" ANDROID_SDK_ROOT="$(cd "$(dirname -- "$ANDROID_SDK_ROOT")" >/dev/null; pwd -P)/$(basename -- "$ANDROID_SDK_ROOT")"
ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION" ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION"
OPENSSL_INSTALL_DIR="$(cd "$(dirname -- "$OPENSSL_INSTALL_DIR")" >/dev/null; pwd -P)/$(basename -- "$OPENSSL_INSTALL_DIR")"
echo "Generating Javadoc documentation..." echo "Generating Javadoc documentation..."
cp "$ANDROID_SDK_ROOT/platforms/android-33/android.jar" . || exit 1 cp "$ANDROID_SDK_ROOT/platforms/android-33/android.jar" . || exit 1
@ -54,7 +56,7 @@ echo "Building TDLib..."
for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
mkdir -p build-$ABI || exit 1 mkdir -p build-$ABI || exit 1
cd build-$ABI cd build-$ABI
cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake" -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja -DANDROID_ABI=$ABI -DANDROID_STL=$ANDROID_STL -DANDROID_PLATFORM=android-16 .. || exit 1 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake" -DOPENSSL_ROOT_DIR="$OPENSSL_INSTALL_DIR/$ABI" -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja -DANDROID_ABI=$ABI -DANDROID_STL=$ANDROID_STL -DANDROID_PLATFORM=android-16 .. || exit 1
cmake --build . || exit 1 cmake --build . || exit 1
cd .. cd ..
@ -73,6 +75,7 @@ for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
done done
echo "Compressing..." echo "Compressing..."
rm -f tdlib.zip tdlib-debug.zip || exit 1
jar -cMf tdlib-debug.zip tdlib || exit 1 jar -cMf tdlib-debug.zip tdlib || exit 1
rm tdlib/libs/*/*.debug || exit 1 rm tdlib/libs/*/*.debug || exit 1
jar -cMf tdlib.zip tdlib || exit 1 jar -cMf tdlib.zip tdlib || exit 1