summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/example/android
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/example/android')
-rw-r--r--protocols/Telegram/tdlib/td/example/android/.gitignore3
-rw-r--r--protocols/Telegram/tdlib/td/example/android/AddIntDef.php51
-rw-r--r--protocols/Telegram/tdlib/td/example/android/CMakeLists.txt48
-rw-r--r--protocols/Telegram/tdlib/td/example/android/Dockerfile26
-rw-r--r--protocols/Telegram/tdlib/td/example/android/README.md24
-rw-r--r--protocols/Telegram/tdlib/td/example/android/build-openssl.sh78
-rw-r--r--protocols/Telegram/tdlib/td/example/android/build-tdlib.sh90
-rw-r--r--protocols/Telegram/tdlib/td/example/android/check-environment.sh51
-rw-r--r--protocols/Telegram/tdlib/td/example/android/fetch-sdk.sh30
9 files changed, 401 insertions, 0 deletions
diff --git a/protocols/Telegram/tdlib/td/example/android/.gitignore b/protocols/Telegram/tdlib/td/example/android/.gitignore
new file mode 100644
index 0000000000..7547413bf5
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/.gitignore
@@ -0,0 +1,3 @@
+SDK/
+tdlib/
+third-party/
diff --git a/protocols/Telegram/tdlib/td/example/android/AddIntDef.php b/protocols/Telegram/tdlib/td/example/android/AddIntDef.php
new file mode 100644
index 0000000000..d4ae4a65bd
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/AddIntDef.php
@@ -0,0 +1,51 @@
+<?php
+ if ($argc !== 2) {
+ exit();
+ }
+ $file = file_get_contents($argv[1]);
+
+ if (strpos($file, 'androidx.annotation.IntDef') !== false) {
+ exit();
+ }
+
+ $file = str_replace('import androidx.annotation.Nullable;', 'import androidx.annotation.IntDef;'.PHP_EOL.
+ 'import androidx.annotation.Nullable;'.PHP_EOL.
+ PHP_EOL.
+ 'import java.lang.annotation.Retention;'.PHP_EOL.
+ 'import java.lang.annotation.RetentionPolicy;'.PHP_EOL, $file);
+
+ preg_match_all('/public static class ([A-Za-z0-9]+) extends ([A-Za-z0-9]+)/', $file, $matches, PREG_SET_ORDER);
+ $children = [];
+ foreach ($matches as $val) {
+ if ($val[2] === 'Object') {
+ continue;
+ }
+
+ $children[$val[2]][] = ' '.$val[1].'.CONSTRUCTOR';
+ }
+
+ $file = preg_replace_callback('/public abstract static class ([A-Za-z0-9]+)(<R extends Object>)? extends Object [{]/',
+ function ($val) use ($children) {
+ $values = implode(','.PHP_EOL, $children[$val[1]]);
+ return $val[0].<<<EOL
+
+ /**
+ * Describes possible values returned by getConstructor().
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+$values
+ })
+ public @interface Constructors {}
+
+ /**
+ * @return identifier uniquely determining type of the object.
+ */
+ @Constructors
+ @Override
+ public abstract int getConstructor();
+EOL;
+ },
+ $file);
+
+ file_put_contents($argv[1], $file);
diff --git a/protocols/Telegram/tdlib/td/example/android/CMakeLists.txt b/protocols/Telegram/tdlib/td/example/android/CMakeLists.txt
new file mode 100644
index 0000000000..a31b1fc951
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/CMakeLists.txt
@@ -0,0 +1,48 @@
+cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)
+
+project(TdAndroid VERSION 1.0 LANGUAGES CXX)
+
+option(TD_ENABLE_JNI "Enable JNI-compatible TDLib API" ON)
+
+set(TD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)
+
+if (CMAKE_CROSSCOMPILING)
+ set(CMAKE_MODULE_PATH "${TD_DIR}/CMake")
+
+ include(TdSetUpCompiler)
+ td_set_up_compiler()
+ string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -flto=thin -Oz")
+
+ list(APPEND CMAKE_FIND_ROOT_PATH "${OPENSSL_ROOT_DIR}")
+ add_subdirectory(${TD_DIR} td)
+
+ add_library(tdjni SHARED "${TD_DIR}/example/java/td_jni.cpp")
+
+ target_link_libraries(tdjni PRIVATE Td::TdStatic)
+ target_compile_definitions(tdjni PRIVATE PACKAGE_NAME="org/drinkless/tdlib")
+
+ add_custom_command(TARGET tdjni POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:tdjni> $<TARGET_FILE:tdjni>.debug
+ COMMAND ${CMAKE_STRIP} --strip-debug --strip-unneeded $<TARGET_FILE:tdjni>.debug -o $<TARGET_FILE:tdjni>)
+else()
+ add_subdirectory(${TD_DIR} td)
+
+ set(TD_API_JAVA_PACKAGE "org/drinkless/tdlib")
+ set(TD_API_JAVA_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${TD_API_JAVA_PACKAGE}/TdApi.java")
+ set(TD_API_TLO_PATH "${TD_DIR}/td/generate/auto/tlo/td_api.tlo")
+ set(TD_API_TL_PATH "${TD_DIR}/td/generate/scheme/td_api.tl")
+ set(JAVADOC_TL_DOCUMENTATION_GENERATOR_PATH "${TD_DIR}/td/generate/JavadocTlDocumentationGenerator.php")
+ set(GENERATE_JAVA_CMD td_generate_java_api TdApi ${TD_API_TLO_PATH} ${CMAKE_CURRENT_SOURCE_DIR} ${TD_API_JAVA_PACKAGE})
+ if (PHP_EXECUTABLE)
+ set(GENERATE_JAVA_CMD ${GENERATE_JAVA_CMD} &&
+ ${PHP_EXECUTABLE} ${JAVADOC_TL_DOCUMENTATION_GENERATOR_PATH} ${TD_API_TL_PATH} ${TD_API_JAVA_PATH} androidx.annotation.Nullable @Nullable &&
+ ${PHP_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/AddIntDef.php ${TD_API_JAVA_PATH})
+ endif()
+
+ file(MAKE_DIRECTORY ${TD_API_JAVA_PACKAGE})
+ add_custom_target(tl_generate_java
+ COMMAND ${GENERATE_JAVA_CMD}
+ COMMENT "Generate Java TL source files"
+ DEPENDS td_generate_java_api tl_generate_tlo ${TD_API_TLO_PATH} ${TD_API_TL_PATH}
+ )
+endif()
diff --git a/protocols/Telegram/tdlib/td/example/android/Dockerfile b/protocols/Telegram/tdlib/td/example/android/Dockerfile
new file mode 100644
index 0000000000..310e8f7eb1
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/Dockerfile
@@ -0,0 +1,26 @@
+FROM --platform=linux/amd64 ubuntu:22.04 as build
+
+RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -yq default-jdk g++ git gperf make perl php-cli unzip wget && rm -rf /var/lib/apt/lists/*
+
+WORKDIR /home
+
+ARG ANDROID_NDK_VERSION=23.2.8568313
+COPY ./check-environment.sh ./fetch-sdk.sh ./
+RUN ./fetch-sdk.sh SDK "$ANDROID_NDK_VERSION"
+
+ARG OPENSSL_VERSION=OpenSSL_1_1_1t
+COPY ./build-openssl.sh ./
+RUN ./build-openssl.sh SDK "$ANDROID_NDK_VERSION" openssl "$OPENSSL_VERSION"
+
+ADD "https://api.github.com/repos/tdlib/td/git/refs/heads/master" version.json
+ARG COMMIT_HASH=master
+RUN git clone https://github.com/tdlib/td.git && cd td && git checkout "$COMMIT_HASH"
+RUN cd td && git merge-base --is-ancestor bcd89728c3b93b67448b93b4863dc5bd4e122a4c "$COMMIT_HASH"
+
+ARG ANDROID_STL=c++_static
+RUN td/example/android/build-tdlib.sh SDK "$ANDROID_NDK_VERSION" openssl "$ANDROID_STL" && rm -rf td/example/android/build-*
+
+
+FROM scratch
+
+COPY --from=build /home/td/example/android/tdlib/tdlib* /
diff --git a/protocols/Telegram/tdlib/td/example/android/README.md b/protocols/Telegram/tdlib/td/example/android/README.md
new file mode 100644
index 0000000000..6fa34fb6d2
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/README.md
@@ -0,0 +1,24 @@
+# TDLib Android example
+
+This is an example of building `TDLib` for Android.
+You need a Bash shell on Linux, macOS, or Windows with some common tools, a C++ compiler, JDK, PHP, perl, and gperf pre-installed.
+
+## Building TDLib for Android
+
+* Run the script `./check-environment.sh` to check that you have all required Unix tools and Java utilities. If the script exits with an error message, install the missing tool.
+* Run the script `./fetch-sdk.sh` to download Android SDK to a local directory.
+* Run the script `./build-openssl.sh` to download and build OpenSSL for Android.
+* Run the script `./build-tdlib.sh` to build TDLib for Android.
+* The built libraries are now located in the `tdlib/libs` directory, corresponding Java code is located in the `tdlib/java` directory, and standalone Java documentation can be found in the `tdlib/javadoc` directory. You can also use archives `tdlib/tdlib.zip` and `tdlib/tdlib-debug.zip`, which contain all aforementioned data.
+
+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 and CMake 3.22.1.
+
+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`.
+
+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 and better performance than newer OpenSSL versions.
+
+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.
+
+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 tdlib directory as specified.
diff --git a/protocols/Telegram/tdlib/td/example/android/build-openssl.sh b/protocols/Telegram/tdlib/td/example/android/build-openssl.sh
new file mode 100644
index 0000000000..e4b82e06be
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/build-openssl.sh
@@ -0,0 +1,78 @@
+#!/usr/bin/env bash
+
+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_1t} # openssl-3.1.0
+
+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."
+ exit 1
+fi
+
+if [ -e "$OPENSSL_INSTALL_DIR" ] ; then
+ echo "Error: file or directory \"$OPENSSL_INSTALL_DIR\" already exists. Delete it manually to proceed."
+ exit 1
+fi
+
+source ./check-environment.sh || exit 1
+
+mkdir -p $OPENSSL_INSTALL_DIR || exit 1
+
+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")"
+
+cd $(dirname $0)
+
+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
+rm -rf ./openssl-$OPENSSL_VERSION || exit 1
+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_HOME=$ANDROID_NDK_ROOT # for OpenSSL 1.1.1
+PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/bin:$PATH
+
+if ! clang --help >/dev/null 2>&1 ; then
+ echo "Error: failed to run clang from Android NDK."
+ if [[ "$OS_NAME" == "linux" ]] ; then
+ echo "Prebuilt Android NDK binaries are linked against glibc, so glibc must be installed."
+ fi
+ exit 1
+fi
+
+ANDROID_API32=16
+ANDROID_API64=21
+if [[ ${ANDROID_NDK_VERSION%%.*} -ge 24 ]] ; then
+ ANDROID_API32=19
+fi
+
+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
+ elif [[ $ABI == "x86_64" ]] ; then
+ ./Configure android-x86_64 no-shared -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
+ elif [[ $ABI == "arm64-v8a" ]] ; then
+ ./Configure android-arm64 no-shared -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
+
+ make depend -s || exit 1
+ 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
+ cp -r include $OPENSSL_INSTALL_DIR/$ABI/ || exit 1
+
+ make distclean || exit 1
+done
+
+cd ..
+
+rm -rf ./openssl-$OPENSSL_VERSION || exit 1
diff --git a/protocols/Telegram/tdlib/td/example/android/build-tdlib.sh b/protocols/Telegram/tdlib/td/example/android/build-tdlib.sh
new file mode 100644
index 0000000000..1ff9ae7af2
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/build-tdlib.sh
@@ -0,0 +1,90 @@
+#!/usr/bin/env bash
+
+ANDROID_SDK_ROOT=${1:-SDK}
+ANDROID_NDK_VERSION=${2:-23.2.8568313}
+OPENSSL_INSTALL_DIR=${3:-third-party/openssl}
+ANDROID_STL=${4:-c++_static}
+
+if [ "$ANDROID_STL" != "c++_static" ] && [ "$ANDROID_STL" != "c++_shared" ] ; then
+ echo 'Error: ANDROID_STL must be either "c++_static" or "c++_shared".'
+ exit 1
+fi
+
+source ./check-environment.sh || exit 1
+
+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."
+ exit 1
+fi
+
+if [ ! -d "$OPENSSL_INSTALL_DIR" ] ; then
+ echo "Error: directory \"$OPENSSL_INSTALL_DIR\" doesn't exists. Run ./build-openssl.sh first."
+ exit 1
+fi
+
+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"
+OPENSSL_INSTALL_DIR="$(cd "$(dirname -- "$OPENSSL_INSTALL_DIR")" >/dev/null; pwd -P)/$(basename -- "$OPENSSL_INSTALL_DIR")"
+PATH=$ANDROID_SDK_ROOT/cmake/3.22.1/bin:$PATH
+
+cd $(dirname $0)
+
+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
+
+echo "Generating TDLib source files..."
+mkdir -p build-native || exit 1
+cd build-native
+cmake .. || exit 1
+cmake --build . --target prepare_cross_compiling || exit 1
+cmake --build . --target tl_generate_java || exit 1
+cd ..
+php AddIntDef.php org/drinkless/tdlib/TdApi.java || exit 1
+
+echo "Copying Java source files..."
+rm -rf tdlib || exit 1
+mkdir -p tdlib/java/org/drinkless/tdlib || exit 1
+cp -p {../../example,tdlib}/java/org/drinkless/tdlib/Client.java || exit 1
+mv {,tdlib/java/}org/drinkless/tdlib/TdApi.java || exit 1
+rm -rf org || exit 1
+
+echo "Generating Javadoc documentation..."
+cp "$ANDROID_SDK_ROOT/platforms/android-33/android.jar" . || exit 1
+JAVADOC_SEPARATOR=$([ "$OS_NAME" == "win" ] && echo ";" || echo ":")
+javadoc -d tdlib/javadoc -encoding UTF-8 -charset UTF-8 -classpath "android.jar${JAVADOC_SEPARATOR}annotation-1.4.0.jar" -quiet -sourcepath tdlib/java org.drinkless.tdlib || exit 1
+rm android.jar annotation-1.4.0.jar || exit 1
+
+echo "Building TDLib..."
+for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
+ mkdir -p build-$ABI || exit 1
+ cd build-$ABI
+ 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
+ cd ..
+
+ mkdir -p tdlib/libs/$ABI/ || exit 1
+ cp -p build-$ABI/libtd*.so* tdlib/libs/$ABI/ || exit 1
+ if [[ "$ANDROID_STL" == "c++_shared" ]] ; then
+ if [[ "$ABI" == "arm64-v8a" ]] ; then
+ FULL_ABI="aarch64-linux-android"
+ elif [[ "$ABI" == "armeabi-v7a" ]] ; then
+ FULL_ABI="arm-linux-androideabi"
+ elif [[ "$ABI" == "x86_64" ]] ; then
+ FULL_ABI="x86_64-linux-android"
+ elif [[ "$ABI" == "x86" ]] ; then
+ FULL_ABI="i686-linux-android"
+ fi
+ 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
+done
+
+echo "Compressing..."
+rm -f tdlib.zip tdlib-debug.zip || exit 1
+jar -cMf tdlib-debug.zip tdlib || exit 1
+rm tdlib/libs/*/*.debug || exit 1
+jar -cMf tdlib.zip tdlib || exit 1
+mv tdlib.zip tdlib-debug.zip tdlib || exit 1
+
+echo "Done."
diff --git a/protocols/Telegram/tdlib/td/example/android/check-environment.sh b/protocols/Telegram/tdlib/td/example/android/check-environment.sh
new file mode 100644
index 0000000000..249df33987
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/check-environment.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+
+# The script checks that all needed tools are installed and sets OS_NAME, HOST_ARCH, and WGET variables
+
+if [[ "$OSTYPE" == "linux"* ]] ; then
+ OS_NAME="linux"
+ HOST_ARCH="linux-x86_64"
+elif [[ "$OSTYPE" == "darwin"* ]] ; then
+ OS_NAME="mac"
+ HOST_ARCH="darwin-x86_64"
+elif [[ "$OSTYPE" == "msys" ]] ; then
+ OS_NAME="win"
+ HOST_ARCH="windows-x86_64"
+else
+ echo "Error: this script supports only Bash shell on Linux, macOS, or Windows."
+ exit 1
+fi
+
+if which wget >/dev/null 2>&1 ; then
+ WGET="wget -q"
+elif which curl >/dev/null 2>&1 ; then
+ WGET="curl -sfLO"
+else
+ echo "Error: this script requires either curl or wget tool installed."
+ exit 1
+fi
+
+for TOOL_NAME in gperf jar java javadoc make perl php sed tar yes unzip ; do
+ if ! which "$TOOL_NAME" >/dev/null 2>&1 ; then
+ echo "Error: this script requires $TOOL_NAME tool installed."
+ exit 1
+ fi
+done
+
+if [[ $(which make) = *" "* ]] ; then
+ echo "Error: OpenSSL expects that full path to make tool doesn't contain spaces. Move it to some other place."
+ exit 1
+fi
+
+if ! perl -MExtUtils::MakeMaker -MLocale::Maketext::Simple -MPod::Usage -e '' >/dev/null 2>&1 ; then
+ echo "Error: Perl installation is broken."
+ if [[ "$OSTYPE" == "msys" ]] ; then
+ echo "For Git Bash you need to manually copy ExtUtils, Locale and Pod modules to /usr/share/perl5/core_perl from any compatible Perl installation."
+ fi
+ exit 1
+fi
+
+if ! java --help >/dev/null 2>&1 ; then
+ echo "Error: Java installation is broken. Install JDK from https://www.oracle.com/java/technologies/downloads/."
+ exit 1
+fi
diff --git a/protocols/Telegram/tdlib/td/example/android/fetch-sdk.sh b/protocols/Telegram/tdlib/td/example/android/fetch-sdk.sh
new file mode 100644
index 0000000000..61d93170a5
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/example/android/fetch-sdk.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+ANDROID_SDK_ROOT=${1:-SDK}
+ANDROID_NDK_VERSION=${2:-23.2.8568313}
+
+if [ -e "$ANDROID_SDK_ROOT" ] ; then
+ echo "Error: file or directory \"$ANDROID_SDK_ROOT\" already exists. Delete it manually to proceed."
+ exit 1
+fi
+
+source ./check-environment.sh || exit 1
+
+SDKMANAGER="./sdkmanager"
+if [[ "$OS_NAME" == "win" ]] ; then
+ SDKMANAGER="./sdkmanager.bat"
+fi
+
+echo "Downloading SDK Manager..."
+mkdir -p "$ANDROID_SDK_ROOT" || exit 1
+cd "$ANDROID_SDK_ROOT" || exit 1
+$WGET "https://dl.google.com/android/repository/commandlinetools-$OS_NAME-8512546_latest.zip" || exit 1
+mkdir -p cmdline-tools || exit 1
+unzip -qq "commandlinetools-$OS_NAME-8512546_latest.zip" -d cmdline-tools || exit 1
+rm "commandlinetools-$OS_NAME-8512546_latest.zip" || exit 1
+mv cmdline-tools/* cmdline-tools/latest/ || exit 1
+
+echo "Installing required SDK tools..."
+cd cmdline-tools/latest/bin/ || exit 1
+yes | $SDKMANAGER --licenses >/dev/null || exit 1
+$SDKMANAGER --install "ndk;$ANDROID_NDK_VERSION" "cmake;3.22.1" "build-tools;33.0.0" "platforms;android-33" > /dev/null || exit 1