From 0da30b78577d46e7628d503f3c87eda9479ba1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 17:44:57 +0200 Subject: [PATCH 01/17] Remove obsolete `autogen.sh` usage for OpenSSL build The OpenSSL project does not contain an `autogen.sh` file anymore, which was causing an error message when building the libraries. --- scripts/compile_libs/gen_libs.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/compile_libs/gen_libs.sh b/scripts/compile_libs/gen_libs.sh index 9b5408909..bf61b6f13 100755 --- a/scripts/compile_libs/gen_libs.sh +++ b/scripts/compile_libs/gen_libs.sh @@ -75,16 +75,11 @@ cd compile_libs || exit 1 # start with openssl ( - _WAS_THERE_SSLFILE=1 if [ ! -d "openssl" ]; then git clone https://github.com/openssl/openssl openssl - _WAS_THERE_SSLFILE=0 fi ( cd openssl || exit 1 - if [[ "$_WAS_THERE_SSLFILE" == 0 ]]; then - ./autogen.sh - fi cp "${CURDIR}"/scripts/compile_libs/make_lib_openssl.sh make_lib_openssl.sh ./make_lib_openssl.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" ) From 2844ad7239e32ce4719845aff0d87aa51fd80134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 17:57:13 +0200 Subject: [PATCH 02/17] Remove redundant `OS_NAME_PATH` variable This variable was simply assigned the same value as the `OS_NAME` variable. --- scripts/compile_libs/gen_libs.sh | 68 ++++++++++++++------------------ 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/scripts/compile_libs/gen_libs.sh b/scripts/compile_libs/gen_libs.sh index bf61b6f13..c27455e52 100755 --- a/scripts/compile_libs/gen_libs.sh +++ b/scripts/compile_libs/gen_libs.sh @@ -20,16 +20,6 @@ if [[ "${OS_NAME}" == "webasm" ]]; then LINKFLAGS="-pthread -O3 -g -s USE_PTHREADS=1 -s ASYNCIFY=1 -s WASM=1" fi -if [[ "${OS_NAME}" == "android" ]]; then - OS_NAME_PATH="android" -elif [[ "${OS_NAME}" == "windows" ]]; then - OS_NAME_PATH="windows" -elif [[ "${OS_NAME}" == "linux" ]]; then - OS_NAME_PATH="linux" -elif [[ "${OS_NAME}" == "webasm" ]]; then - OS_NAME_PATH="webasm" -fi - COMP_HAS_ARM32=0 COMP_HAS_ARM64=0 COMP_HAS_x86=0 @@ -141,29 +131,29 @@ function copy_arches_for_lib() { mkdir ddnet-libs function _copy_curl() { - mkdir -p ddnet-libs/curl/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/curl/build_"$OS_NAME"_"$1"/lib/libcurl.a ddnet-libs/curl/"$OS_NAME_PATH"/lib"$2"/libcurl.a + mkdir -p ddnet-libs/curl/"$OS_NAME"/lib"$2" + cp compile_libs/curl/build_"$OS_NAME"_"$1"/lib/libcurl.a ddnet-libs/curl/"$OS_NAME"/lib"$2"/libcurl.a } copy_arches_for_lib _copy_curl mkdir ddnet-libs function _copy_freetype2() { - mkdir -p ddnet-libs/freetype/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/freetype2/build_"$OS_NAME"_"$1"/libfreetype.a ddnet-libs/freetype/"$OS_NAME_PATH"/lib"$2"/libfreetype.a + mkdir -p ddnet-libs/freetype/"$OS_NAME"/lib"$2" + cp compile_libs/freetype2/build_"$OS_NAME"_"$1"/libfreetype.a ddnet-libs/freetype/"$OS_NAME"/lib"$2"/libfreetype.a } copy_arches_for_lib _copy_freetype2 mkdir ddnet-libs function _copy_sdl() { - mkdir -p ddnet-libs/sdl/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2.a ddnet-libs/sdl/"$OS_NAME_PATH"/lib"$2"/libSDL2.a - cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2main.a ddnet-libs/sdl/"$OS_NAME_PATH"/lib"$2"/libSDL2main.a - if [ ! -d "ddnet-libs/sdl/include/$OS_NAME_PATH" ]; then - mkdir -p ddnet-libs/sdl/include/"$OS_NAME_PATH" + mkdir -p ddnet-libs/sdl/"$OS_NAME"/lib"$2" + cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2.a ddnet-libs/sdl/"$OS_NAME"/lib"$2"/libSDL2.a + cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2main.a ddnet-libs/sdl/"$OS_NAME"/lib"$2"/libSDL2main.a + if [ ! -d "ddnet-libs/sdl/include/$OS_NAME" ]; then + mkdir -p ddnet-libs/sdl/include/"$OS_NAME" fi - cp -R compile_libs/sdl/include/* ddnet-libs/sdl/include/"$OS_NAME_PATH" + cp -R compile_libs/sdl/include/* ddnet-libs/sdl/include/"$OS_NAME" } copy_arches_for_lib _copy_sdl @@ -177,44 +167,44 @@ fi mkdir ddnet-libs function _copy_ogg() { - mkdir -p ddnet-libs/opus/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/ogg/build_"$OS_NAME"_"$1"/libogg.a ddnet-libs/opus/"$OS_NAME_PATH"/lib"$2"/libogg.a + mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2" + cp compile_libs/ogg/build_"$OS_NAME"_"$1"/libogg.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libogg.a } copy_arches_for_lib _copy_ogg mkdir ddnet-libs function _copy_opus() { - mkdir -p ddnet-libs/opus/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/opus/build_"$OS_NAME"_"$1"/libopus.a ddnet-libs/opus/"$OS_NAME_PATH"/lib"$2"/libopus.a + mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2" + cp compile_libs/opus/build_"$OS_NAME"_"$1"/libopus.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libopus.a } copy_arches_for_lib _copy_opus mkdir ddnet-libs function _copy_opusfile() { - mkdir -p ddnet-libs/opus/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/opusfile/build_"$OS_NAME"_"$1"/libopusfile.a ddnet-libs/opus/"$OS_NAME_PATH"/lib"$2"/libopusfile.a + mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2" + cp compile_libs/opusfile/build_"$OS_NAME"_"$1"/libopusfile.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libopusfile.a } copy_arches_for_lib _copy_opusfile mkdir ddnet-libs function _copy_sqlite3() { - mkdir -p ddnet-libs/sqlite3/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/sqlite3/build_"$OS_NAME"_"$1"/sqlite3.a ddnet-libs/sqlite3/"$OS_NAME_PATH"/lib"$2"/libsqlite3.a + mkdir -p ddnet-libs/sqlite3/"$OS_NAME"/lib"$2" + cp compile_libs/sqlite3/build_"$OS_NAME"_"$1"/sqlite3.a ddnet-libs/sqlite3/"$OS_NAME"/lib"$2"/libsqlite3.a } copy_arches_for_lib _copy_sqlite3 mkdir ddnet-libs function _copy_openssl() { - mkdir -p ddnet-libs/openssl/"$OS_NAME_PATH"/lib"$2" + mkdir -p ddnet-libs/openssl/"$OS_NAME"/lib"$2" mkdir -p ddnet-libs/openssl/include - mkdir -p ddnet-libs/openssl/include/"$OS_NAME_PATH" - cp compile_libs/openssl/build_"$OS_NAME"_"$1"/libcrypto.a ddnet-libs/openssl/"$OS_NAME_PATH"/lib"$2"/libcrypto.a - cp compile_libs/openssl/build_"$OS_NAME"_"$1"/libssl.a ddnet-libs/openssl/"$OS_NAME_PATH"/lib"$2"/libssl.a - cp -R compile_libs/openssl/build_"$OS_NAME"_"$1"/include/* ddnet-libs/openssl/include/"$OS_NAME_PATH" + mkdir -p ddnet-libs/openssl/include/"$OS_NAME" + cp compile_libs/openssl/build_"$OS_NAME"_"$1"/libcrypto.a ddnet-libs/openssl/"$OS_NAME"/lib"$2"/libcrypto.a + cp compile_libs/openssl/build_"$OS_NAME"_"$1"/libssl.a ddnet-libs/openssl/"$OS_NAME"/lib"$2"/libssl.a + cp -R compile_libs/openssl/build_"$OS_NAME"_"$1"/include/* ddnet-libs/openssl/include/"$OS_NAME" cp -R compile_libs/openssl/include/* ddnet-libs/openssl/include } @@ -232,21 +222,21 @@ function _copy_zlib() { cd build_"$OS_NAME"_"$1" || exit 1 find . -maxdepth 1 -iname '*.h' -print0 | while IFS= read -r -d $'\0' file; do - mkdir -p ../../../ddnet-libs/zlib/include/"$OS_NAME_PATH"/"$(dirname "$file")" - cp "$file" ../../../ddnet-libs/zlib/include/"$OS_NAME_PATH"/"$(dirname "$file")" + mkdir -p ../../../ddnet-libs/zlib/include/"$OS_NAME"/"$(dirname "$file")" + cp "$file" ../../../ddnet-libs/zlib/include/"$OS_NAME"/"$(dirname "$file")" done ) - mkdir -p ddnet-libs/zlib/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/zlib/build_"$OS_NAME"_"$1"/libz.a ddnet-libs/zlib/"$OS_NAME_PATH"/lib"$2"/libz.a + mkdir -p ddnet-libs/zlib/"$OS_NAME"/lib"$2" + cp compile_libs/zlib/build_"$OS_NAME"_"$1"/libz.a ddnet-libs/zlib/"$OS_NAME"/lib"$2"/libz.a } copy_arches_for_lib _copy_zlib mkdir ddnet-libs function _copy_png() { - mkdir -p ddnet-libs/png/"$OS_NAME_PATH"/lib"$2" - cp compile_libs/png/build_"$OS_NAME"_"$1"/libpng16.a ddnet-libs/png/"$OS_NAME_PATH"/lib"$2"/libpng16.a + mkdir -p ddnet-libs/png/"$OS_NAME"/lib"$2" + cp compile_libs/png/build_"$OS_NAME"_"$1"/libpng16.a ddnet-libs/png/"$OS_NAME"/lib"$2"/libpng16.a } copy_arches_for_lib _copy_png From e9581b87bae7a39f22245892d5fad1869d2d2f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:05:54 +0200 Subject: [PATCH 03/17] Ensure specified target system for buiding libraries is valid Abort building libraries if the specified target system is not one of the supported values. --- scripts/compile_libs/gen_libs.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/compile_libs/gen_libs.sh b/scripts/compile_libs/gen_libs.sh index c27455e52..8a5b13843 100755 --- a/scripts/compile_libs/gen_libs.sh +++ b/scripts/compile_libs/gen_libs.sh @@ -7,7 +7,7 @@ if [ -z ${1+x} ]; then fi if [ -z ${2+x} ]; then - echo "Specify the target system" + echo "Specify the target system: android, linux, window, webasm" exit 1 fi @@ -38,6 +38,9 @@ elif [[ "${OS_NAME}" == "windows" ]]; then COMP_HAS_x64=1 elif [[ "${OS_NAME}" == "webasm" ]]; then COMP_HAS_WEBASM=1 +else + echo "Specify the target system: android, linux, window, webasm" + exit 1 fi mkdir -p "$1" From 60733bc0330254105f0916f8ae842c2777bf26ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:06:12 +0200 Subject: [PATCH 04/17] Remove redundant check for existing directory with `mkdir -p` The `mkdir -p` command is already idempotent so separately checking whether the directory exists is not necessary. --- scripts/compile_libs/gen_libs.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/compile_libs/gen_libs.sh b/scripts/compile_libs/gen_libs.sh index 8a5b13843..4cfd72ddb 100755 --- a/scripts/compile_libs/gen_libs.sh +++ b/scripts/compile_libs/gen_libs.sh @@ -153,9 +153,7 @@ function _copy_sdl() { mkdir -p ddnet-libs/sdl/"$OS_NAME"/lib"$2" cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2.a ddnet-libs/sdl/"$OS_NAME"/lib"$2"/libSDL2.a cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2main.a ddnet-libs/sdl/"$OS_NAME"/lib"$2"/libSDL2main.a - if [ ! -d "ddnet-libs/sdl/include/$OS_NAME" ]; then - mkdir -p ddnet-libs/sdl/include/"$OS_NAME" - fi + mkdir -p ddnet-libs/sdl/include/"$OS_NAME" cp -R compile_libs/sdl/include/* ddnet-libs/sdl/include/"$OS_NAME" } From 45f619722be1fc46f48d2c1ac0b63b47e8e453ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:11:39 +0200 Subject: [PATCH 05/17] Avoid duplicate creation of `ddnet-libs` directory Avoid error messages due to `ddnet-libs` directory already existing and being created multiple times. --- scripts/compile_libs/gen_libs.sh | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/scripts/compile_libs/gen_libs.sh b/scripts/compile_libs/gen_libs.sh index 4cfd72ddb..f9134c03c 100755 --- a/scripts/compile_libs/gen_libs.sh +++ b/scripts/compile_libs/gen_libs.sh @@ -113,6 +113,7 @@ fi ) cd .. +mkdir -p ddnet-libs function copy_arches_for_lib() { if [[ "$COMP_HAS_ARM32" == "1" ]]; then @@ -132,23 +133,18 @@ function copy_arches_for_lib() { fi } -mkdir ddnet-libs function _copy_curl() { mkdir -p ddnet-libs/curl/"$OS_NAME"/lib"$2" cp compile_libs/curl/build_"$OS_NAME"_"$1"/lib/libcurl.a ddnet-libs/curl/"$OS_NAME"/lib"$2"/libcurl.a } - copy_arches_for_lib _copy_curl -mkdir ddnet-libs function _copy_freetype2() { mkdir -p ddnet-libs/freetype/"$OS_NAME"/lib"$2" cp compile_libs/freetype2/build_"$OS_NAME"_"$1"/libfreetype.a ddnet-libs/freetype/"$OS_NAME"/lib"$2"/libfreetype.a } - copy_arches_for_lib _copy_freetype2 -mkdir ddnet-libs function _copy_sdl() { mkdir -p ddnet-libs/sdl/"$OS_NAME"/lib"$2" cp compile_libs/sdl/build_"$OS_NAME"_"$1"/libSDL2.a ddnet-libs/sdl/"$OS_NAME"/lib"$2"/libSDL2.a @@ -156,7 +152,6 @@ function _copy_sdl() { mkdir -p ddnet-libs/sdl/include/"$OS_NAME" cp -R compile_libs/sdl/include/* ddnet-libs/sdl/include/"$OS_NAME" } - copy_arches_for_lib _copy_sdl # copy java code from SDL2 @@ -166,39 +161,30 @@ if [[ "$OS_NAME" == "android" ]]; then cp -R compile_libs/sdl/android-project/app/src/main/java/org ddnet-libs/sdl/java/ fi -mkdir ddnet-libs function _copy_ogg() { mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2" cp compile_libs/ogg/build_"$OS_NAME"_"$1"/libogg.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libogg.a } - copy_arches_for_lib _copy_ogg -mkdir ddnet-libs function _copy_opus() { mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2" cp compile_libs/opus/build_"$OS_NAME"_"$1"/libopus.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libopus.a } - copy_arches_for_lib _copy_opus -mkdir ddnet-libs function _copy_opusfile() { mkdir -p ddnet-libs/opus/"$OS_NAME"/lib"$2" cp compile_libs/opusfile/build_"$OS_NAME"_"$1"/libopusfile.a ddnet-libs/opus/"$OS_NAME"/lib"$2"/libopusfile.a } - copy_arches_for_lib _copy_opusfile -mkdir ddnet-libs function _copy_sqlite3() { mkdir -p ddnet-libs/sqlite3/"$OS_NAME"/lib"$2" cp compile_libs/sqlite3/build_"$OS_NAME"_"$1"/sqlite3.a ddnet-libs/sqlite3/"$OS_NAME"/lib"$2"/libsqlite3.a } - copy_arches_for_lib _copy_sqlite3 -mkdir ddnet-libs function _copy_openssl() { mkdir -p ddnet-libs/openssl/"$OS_NAME"/lib"$2" mkdir -p ddnet-libs/openssl/include @@ -208,10 +194,8 @@ function _copy_openssl() { cp -R compile_libs/openssl/build_"$OS_NAME"_"$1"/include/* ddnet-libs/openssl/include/"$OS_NAME" cp -R compile_libs/openssl/include/* ddnet-libs/openssl/include } - copy_arches_for_lib _copy_openssl -mkdir ddnet-libs function _copy_zlib() { # copy headers ( @@ -231,13 +215,10 @@ function _copy_zlib() { mkdir -p ddnet-libs/zlib/"$OS_NAME"/lib"$2" cp compile_libs/zlib/build_"$OS_NAME"_"$1"/libz.a ddnet-libs/zlib/"$OS_NAME"/lib"$2"/libz.a } - copy_arches_for_lib _copy_zlib -mkdir ddnet-libs function _copy_png() { mkdir -p ddnet-libs/png/"$OS_NAME"/lib"$2" cp compile_libs/png/build_"$OS_NAME"_"$1"/libpng16.a ddnet-libs/png/"$OS_NAME"/lib"$2"/libpng16.a } - copy_arches_for_lib _copy_png From 930836f349337888f7d953af1cd552b865f8989b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:08:05 +0200 Subject: [PATCH 06/17] Split `compile_source` function for readability Split the `compile_source` function into `compile_source_android` and `compile_source_webasm` instead of using a parameter to switch between the functionality. --- scripts/compile_libs/cmake_lib_compile.sh | 124 +++++++++++----------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/scripts/compile_libs/cmake_lib_compile.sh b/scripts/compile_libs/cmake_lib_compile.sh index 066e0c24b..775584e11 100755 --- a/scripts/compile_libs/cmake_lib_compile.sh +++ b/scripts/compile_libs/cmake_lib_compile.sh @@ -15,73 +15,73 @@ fi COMPILEFLAGS=$3 LINKFLAGS=$4 -function compile_source() { - if [[ "${4}" == "android" ]]; then - cmake \ - -H. \ - -G "Unix Makefiles" \ - -DCMAKE_BUILD_TYPE=Release \ - -DANDROID_PLATFORM="android-$1" \ - -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ - -DANDROID_NDK="$ANDROID_NDK_HOME" \ - -DANDROID_ABI="${3}" \ - -DANDROID_ARM_NEON=TRUE \ - -DCMAKE_ANDROID_NDK="$ANDROID_NDK_HOME" \ - -DCMAKE_SYSTEM_NAME=Android \ - -DCMAKE_SYSTEM_VERSION="$1" \ - -DCMAKE_ANDROID_ARCH_ABI="${3}" \ - -B"$2" \ - -DBUILD_SHARED_LIBS=OFF \ - -DHIDAPI_SKIP_LIBUSB=TRUE \ - -DCURL_USE_OPENSSL=ON \ - -DSDL_HIDAPI=OFF \ - -DOP_DISABLE_HTTP=ON \ - -DOP_DISABLE_EXAMPLES=ON \ - -DOP_DISABLE_DOCS=ON \ - -DOPENSSL_ROOT_DIR="$PWD"/../openssl/"$2" \ - -DOPENSSL_CRYPTO_LIBRARY="$PWD"/../openssl/"$2"/libcrypto.a \ - -DOPENSSL_SSL_LIBRARY="$PWD"/../openssl/"$2"/libssl.a \ - -DOPENSSL_INCLUDE_DIR="${PWD}/../openssl/include;${PWD}/../openssl/${2}/include" - ( - cd "$2" || exit 1 - cmake --build . - ) - else - ${5} cmake \ - -H. \ - -DCMAKE_BUILD_TYPE=Release \ - -B"$2" \ - -DSDL_STATIC=TRUE \ - -DFT_DISABLE_HARFBUZZ=ON \ - -DFT_DISABLE_BZIP2=ON \ - -DFT_DISABLE_BROTLI=ON \ - -DFT_REQUIRE_ZLIB=TRUE \ - -DCMAKE_C_FLAGS="$COMPILEFLAGS -DGLEW_STATIC" -DCMAKE_CXX_FLAGS="$COMPILEFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$COMPILEFLAGS" -DCMAKE_C_FLAGS_RELEASE="$COMPILEFLAGS" \ - -DCMAKE_SHARED_LINKER_FLAGS="$LINKFLAGS" -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$LINKFLAGS" \ - -DSDL_PTHREADS=ON -DSDL_THREADS=ON \ - -DCURL_USE_OPENSSL=ON \ - -DOPUS_HARDENING=OFF \ - -DOPUS_STACK_PROTECTOR=OFF \ - -DOPENSSL_ROOT_DIR="$PWD"/../openssl/"$2" \ - -DOPENSSL_CRYPTO_LIBRARY="$PWD"/../openssl/"$2"/libcrypto.a \ - -DOPENSSL_SSL_LIBRARY="$PWD"/../openssl/"$2"/libssl.a \ - -DOPENSSL_INCLUDE_DIR="${PWD}/../openssl/include;${PWD}/../openssl/${2}/include" \ - -DZLIB_LIBRARY="${PWD}/../zlib/${2}/libz.a" -DZLIB_INCLUDE_DIR="${PWD}/../zlib;${PWD}/../zlib/${2}" - ( - cd "$2" || exit 1 - cmake --build . - ) - fi +function compile_source_android() { + cmake \ + -H. \ + -G "Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=Release \ + -DANDROID_PLATFORM="android-$1" \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_NDK="$ANDROID_NDK_HOME" \ + -DANDROID_ABI="${3}" \ + -DANDROID_ARM_NEON=TRUE \ + -DCMAKE_ANDROID_NDK="$ANDROID_NDK_HOME" \ + -DCMAKE_SYSTEM_NAME=Android \ + -DCMAKE_SYSTEM_VERSION="$1" \ + -DCMAKE_ANDROID_ARCH_ABI="${3}" \ + -B"$2" \ + -DBUILD_SHARED_LIBS=OFF \ + -DHIDAPI_SKIP_LIBUSB=TRUE \ + -DCURL_USE_OPENSSL=ON \ + -DSDL_HIDAPI=OFF \ + -DOP_DISABLE_HTTP=ON \ + -DOP_DISABLE_EXAMPLES=ON \ + -DOP_DISABLE_DOCS=ON \ + -DOPENSSL_ROOT_DIR="$PWD"/../openssl/"$2" \ + -DOPENSSL_CRYPTO_LIBRARY="$PWD"/../openssl/"$2"/libcrypto.a \ + -DOPENSSL_SSL_LIBRARY="$PWD"/../openssl/"$2"/libssl.a \ + -DOPENSSL_INCLUDE_DIR="${PWD}/../openssl/include;${PWD}/../openssl/${2}/include" + ( + cd "$2" || exit 1 + cmake --build . + ) +} + +function compile_source_webasm() { + emcmake cmake \ + -H. \ + -DCMAKE_BUILD_TYPE=Release \ + -B"$2" \ + -DSDL_STATIC=TRUE \ + -DFT_DISABLE_HARFBUZZ=ON \ + -DFT_DISABLE_BZIP2=ON \ + -DFT_DISABLE_BROTLI=ON \ + -DFT_REQUIRE_ZLIB=TRUE \ + -DCMAKE_C_FLAGS="$COMPILEFLAGS -DGLEW_STATIC" -DCMAKE_CXX_FLAGS="$COMPILEFLAGS" -DCMAKE_CXX_FLAGS_RELEASE="$COMPILEFLAGS" -DCMAKE_C_FLAGS_RELEASE="$COMPILEFLAGS" \ + -DCMAKE_SHARED_LINKER_FLAGS="$LINKFLAGS" -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$LINKFLAGS" \ + -DSDL_PTHREADS=ON -DSDL_THREADS=ON \ + -DCURL_USE_OPENSSL=ON \ + -DOPUS_HARDENING=OFF \ + -DOPUS_STACK_PROTECTOR=OFF \ + -DOPENSSL_ROOT_DIR="$PWD"/../openssl/"$2" \ + -DOPENSSL_CRYPTO_LIBRARY="$PWD"/../openssl/"$2"/libcrypto.a \ + -DOPENSSL_SSL_LIBRARY="$PWD"/../openssl/"$2"/libssl.a \ + -DOPENSSL_INCLUDE_DIR="${PWD}/../openssl/include;${PWD}/../openssl/${2}/include" \ + -DZLIB_LIBRARY="${PWD}/../zlib/${2}/libz.a" -DZLIB_INCLUDE_DIR="${PWD}/../zlib;${PWD}/../zlib/${2}" + ( + cd "$2" || exit 1 + cmake --build . + ) } if [[ "${2}" == "android" ]]; then - compile_source "$1" build_"$2"_arm armeabi-v7a "$2" "" & - compile_source "$1" build_"$2"_arm64 arm64-v8a "$2" "" & - compile_source "$1" build_"$2"_x86 x86 "$2" "" & - compile_source "$1" build_"$2"_x86_64 x86_64 "$2" "" & + compile_source_android "$1" build_android_arm armeabi-v7a & + compile_source_android "$1" build_android_arm64 arm64-v8a & + compile_source_android "$1" build_android_x86 x86 & + compile_source_android "$1" build_android_x86_64 x86_64 & elif [[ "${2}" == "webasm" ]]; then sed -i "s/include(CheckSizes)//g" CMakeLists.txt - compile_source "$1" build_"$2"_wasm wasm "$2" emcmake & + compile_source_webasm "$1" build_webasm_wasm wasm & fi wait From 69102880c941923cdf69fe9fe4b09147601a055d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:26:39 +0200 Subject: [PATCH 07/17] Remove unused `GE_NO_APK_BUILD` variable This variable is always empty and we don't need to support not building the APK file. --- scripts/android/files/build.sh | 53 ++++++++++++++++------------------ 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/scripts/android/files/build.sh b/scripts/android/files/build.sh index a82a9d815..1a9ac993a 100644 --- a/scripts/android/files/build.sh +++ b/scripts/android/files/build.sh @@ -54,33 +54,30 @@ if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then sed -i "s/android.enableR8.fullMode=true/android.enableR8.fullMode=false/g" gradle.properties fi -if [[ -z ${GE_NO_APK_BUILD} || "${GE_NO_APK_BUILD}" != "1" ]]; then +_RELEASE_TYPE_NAME=debug +_RELEASE_TYPE_APK_NAME= +if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then _RELEASE_TYPE_NAME=debug - _RELEASE_TYPE_APK_NAME= - if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then - _RELEASE_TYPE_NAME=debug - fi - - if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then - _RELEASE_TYPE_NAME=release - _RELEASE_TYPE_APK_NAME= - fi - - APP_BASE_NAME=Gradle - CLASSPATH=gradle-wrapper.jar - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all - if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all builddebug - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleDebug - else - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all buildrelease - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleRelease - fi - cp build/outputs/apk/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".apk "$_APK_BASENAME".apk - - if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all bundleRelease - - cp build/outputs/bundle/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".aab "$_APK_BASENAME".aab - fi +fi + +if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then + _RELEASE_TYPE_NAME=release + _RELEASE_TYPE_APK_NAME= +fi + +APP_BASE_NAME=Gradle +CLASSPATH=gradle-wrapper.jar +java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all +if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then + java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all builddebug + java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleDebug +else + java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all buildrelease + java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleRelease +fi +cp build/outputs/apk/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".apk "$_APK_BASENAME".apk + +if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then + java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all bundleRelease + cp build/outputs/bundle/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".aab "$_APK_BASENAME".aab fi From 6a453d10b4d987131e4fc2a408ca24a01f123b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:27:59 +0200 Subject: [PATCH 08/17] Remove unused `_RELEASE_TYPE_APK_NAME` variable This variable is always empty. --- scripts/android/files/build.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/android/files/build.sh b/scripts/android/files/build.sh index 1a9ac993a..18ef70cce 100644 --- a/scripts/android/files/build.sh +++ b/scripts/android/files/build.sh @@ -55,14 +55,12 @@ if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then fi _RELEASE_TYPE_NAME=debug -_RELEASE_TYPE_APK_NAME= if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then _RELEASE_TYPE_NAME=debug fi if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then _RELEASE_TYPE_NAME=release - _RELEASE_TYPE_APK_NAME= fi APP_BASE_NAME=Gradle @@ -75,9 +73,9 @@ else java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all buildrelease java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleRelease fi -cp build/outputs/apk/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".apk "$_APK_BASENAME".apk +cp build/outputs/apk/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME".apk "$_APK_BASENAME".apk if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all bundleRelease - cp build/outputs/bundle/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME""$_RELEASE_TYPE_APK_NAME".aab "$_APK_BASENAME".aab + cp build/outputs/bundle/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME".aab "$_APK_BASENAME".aab fi From e981d48b2424a9f23be5d3e33201b25561d7d5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:29:46 +0200 Subject: [PATCH 09/17] Extract `build_gradle` function, fix Gradle use without arguments Extract `build_gradle` function to reduce duplicate code for running the Gradle build. Remove the initial invocation of Gradle without a build target, which has no effect and was causing an error message during the build. --- scripts/android/files/build.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/android/files/build.sh b/scripts/android/files/build.sh index 18ef70cce..ada181377 100644 --- a/scripts/android/files/build.sh +++ b/scripts/android/files/build.sh @@ -63,19 +63,20 @@ if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then _RELEASE_TYPE_NAME=release fi -APP_BASE_NAME=Gradle -CLASSPATH=gradle-wrapper.jar -java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all +function build_gradle() { + java "-Dorg.gradle.appname=Gradle" -classpath gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain --warning-mode all "$1" +} + if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all builddebug - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleDebug + build_gradle builddebug + build_gradle assembleDebug else - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all buildrelease - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all assembleRelease + build_gradle buildrelease + build_gradle assembleRelease fi cp build/outputs/apk/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME".apk "$_APK_BASENAME".apk if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then - java "-Dorg.gradle.appname=${APP_BASE_NAME}" -classpath "${CLASSPATH}" org.gradle.wrapper.GradleWrapperMain --warning-mode all bundleRelease + build_gradle bundleRelease cp build/outputs/bundle/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME".aab "$_APK_BASENAME".aab fi From d9686591f0ab21e48532c4cbb1f3d53b042b0b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 11 May 2024 18:34:42 +0200 Subject: [PATCH 10/17] Ensure APK build type parameter is valid Abort build script if the build type parameter value is not valid, instead of assuming the debug build. --- scripts/android/files/build.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/android/files/build.sh b/scripts/android/files/build.sh index ada181377..ef6c2f3cf 100644 --- a/scripts/android/files/build.sh +++ b/scripts/android/files/build.sh @@ -19,6 +19,15 @@ _APK_BASENAME="$1" _APK_PACKAGE_NAME="$2" _APK_BUILD_TYPE="$3" +if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then + _RELEASE_TYPE_NAME=debug +elif [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then + _RELEASE_TYPE_NAME=release +else + printf '\e[31mDid not pass build type to build script: Debug, Release\e[30m\n' + exit 1 +fi + _APK_PACKAGE_FOLDER=$(echo "$_APK_PACKAGE_NAME" | sed 's/\./\//g') sed -i "s/DDNet/${_APK_BASENAME}/g" settings.gradle @@ -54,15 +63,6 @@ if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then sed -i "s/android.enableR8.fullMode=true/android.enableR8.fullMode=false/g" gradle.properties fi -_RELEASE_TYPE_NAME=debug -if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then - _RELEASE_TYPE_NAME=debug -fi - -if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then - _RELEASE_TYPE_NAME=release -fi - function build_gradle() { java "-Dorg.gradle.appname=Gradle" -classpath gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain --warning-mode all "$1" } From 41738f18805c09780854aba3cae1bf29e5a384b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 17 May 2024 19:52:11 +0200 Subject: [PATCH 11/17] Ensure libary is copied successfully, remove unnecessary copies Ensure that the main game library is copied successfully. Remove unnecessary copies of library files that do not exist and are unused, which were causing error messages during the build. --- scripts/android/cmake_android.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/android/cmake_android.sh b/scripts/android/cmake_android.sh index 31503af18..e5544b7a6 100755 --- a/scripts/android/cmake_android.sh +++ b/scripts/android/cmake_android.sh @@ -198,9 +198,7 @@ copy_dummy_files other/icons/DDNet_256x256x32.png src/main/res/mipmap/ic_launche function copy_libs() { mkdir -p "lib/$2" - cp "$_ANDROID_SUB_BUILD_DIR/$1/libDDNet.so" "lib/$2" - cp "$_ANDROID_SUB_BUILD_DIR/$1/libs/libSDL2.so" "lib/$2" - cp "$_ANDROID_SUB_BUILD_DIR/$1/libs/libhidapi.so" "lib/$2" + cp "$_ANDROID_SUB_BUILD_DIR/$1/libDDNet.so" "lib/$2" || exit 1 } if [[ "${_DEFAULT_ANDROID_BUILD}" == "arm" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then From d9f810691b983301d8d53d53b2931d3978b48b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 17 May 2024 19:52:50 +0200 Subject: [PATCH 12/17] Remove duplicate dynamic loading of game library SDL automatically loads the libraries specified in the array returned by the `getLibraries` method, so loading it manually is unnecessary. SDL also has additional error handling to quit the app with an appropriate error message popup if the library could not be loaded, which was not handled previously. --- scripts/android/files/java/org/ddnet/client/NativeMain.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/android/files/java/org/ddnet/client/NativeMain.java b/scripts/android/files/java/org/ddnet/client/NativeMain.java index 890fc8c7f..646ccb509 100644 --- a/scripts/android/files/java/org/ddnet/client/NativeMain.java +++ b/scripts/android/files/java/org/ddnet/client/NativeMain.java @@ -6,16 +6,10 @@ import android.os.Bundle; import android.content.pm.ActivityInfo; public class NativeMain extends SDLActivity { - static { - System.loadLibrary("DDNet"); - } @Override protected String[] getLibraries() { return new String[] { - // disable hid API for now - // "hidapi", - // "SDL2", "DDNet", }; } From c8f0391c62a30aa4ca4d56d368f01ae60dac25c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 17 May 2024 20:00:54 +0200 Subject: [PATCH 13/17] Remove unnecessary `copy_dummy_files_rec` function Create the folder and copy the file manually instead of using a separate function for this, as the function is only used once. --- scripts/android/cmake_android.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/android/cmake_android.sh b/scripts/android/cmake_android.sh index e5544b7a6..474576600 100755 --- a/scripts/android/cmake_android.sh +++ b/scripts/android/cmake_android.sh @@ -172,6 +172,7 @@ printf "\e[36mPreparing gradle build\n" cd "${_DEFAULT_BUILD_FOLDER}" || exit 1 mkdir -p src/main +mkdir -p src/main/res/values mkdir -p src/main/res/mipmap function copy_dummy_files() { @@ -179,11 +180,6 @@ function copy_dummy_files() { cp ../"$1" "$2" } -function copy_dummy_files_rec() { - rm -R ./"$2"/"$1" - cp -R ../"$1" "$2" -} - copy_dummy_files scripts/android/files/build.sh build.sh copy_dummy_files scripts/android/files/gradle-wrapper.jar gradle-wrapper.jar copy_dummy_files scripts/android/files/build.gradle build.gradle @@ -192,7 +188,7 @@ copy_dummy_files scripts/android/files/gradle.properties gradle.properties copy_dummy_files scripts/android/files/proguard-rules.pro proguard-rules.pro copy_dummy_files scripts/android/files/settings.gradle settings.gradle copy_dummy_files scripts/android/files/AndroidManifest.xml src/main/AndroidManifest.xml -copy_dummy_files_rec scripts/android/files/res src/main +copy_dummy_files scripts/android/files/res/values/strings.xml src/main/res/values/strings.xml copy_dummy_files other/icons/DDNet_256x256x32.png src/main/res/mipmap/ic_launcher.png copy_dummy_files other/icons/DDNet_256x256x32.png src/main/res/mipmap/ic_launcher_round.png From 1a3b2eac106e7649d5df6d39a9ed6af8638ee6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 17 May 2024 20:09:24 +0200 Subject: [PATCH 14/17] Abort build script if CMake build failed for any architecture Abort the build script when the CMake build fails for any of the selected architectures. Previously, the build may have continued and caused an APK without the respective library files to be built. --- scripts/android/cmake_android.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/android/cmake_android.sh b/scripts/android/cmake_android.sh index 474576600..976ca87b6 100755 --- a/scripts/android/cmake_android.sh +++ b/scripts/android/cmake_android.sh @@ -151,21 +151,40 @@ mkdir "${_DEFAULT_BUILD_FOLDER}" if [[ "${_DEFAULT_ANDROID_BUILD}" == "arm" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then build_for_type arm armeabi-v7a armv7-linux-androideabi & + PID_BUILD_ARM=$! fi if [[ "${_DEFAULT_ANDROID_BUILD}" == "arm64" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then build_for_type arm64 arm64-v8a aarch64-linux-android & + PID_BUILD_ARM64=$! fi if [[ "${_DEFAULT_ANDROID_BUILD}" == "x86" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then build_for_type x86 x86 i686-linux-android & + PID_BUILD_X86=$! fi if [[ "${_DEFAULT_ANDROID_BUILD}" == "x86_64" || "${_DEFAULT_ANDROID_BUILD}" == "x64" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then build_for_type x86_64 x86_64 x86_64-linux-android & + PID_BUILD_X86_64=$! fi -wait +if [ -n "$PID_BUILD_ARM" ] && ! wait "$PID_BUILD_ARM"; then + printf "\e[31m%s\e[30m\n" "Building for arm failed" + exit 1 +fi +if [ -n "$PID_BUILD_ARM64" ] && ! wait "$PID_BUILD_ARM64"; then + printf "\e[31m%s\e[30m\n" "Building for arm64 failed" + exit 1 +fi +if [ -n "$PID_BUILD_X86" ] && ! wait "$PID_BUILD_X86"; then + printf "\e[31m%s\e[30m\n" "Building for x86 failed" + exit 1 +fi +if [ -n "$PID_BUILD_X86_64" ] && ! wait "$PID_BUILD_X86_64"; then + printf "\e[31m%s\e[30m\n" "Building for x86_64 failed" + exit 1 +fi printf "\e[36mPreparing gradle build\n" From 7de52fd46fe972ec92005b0a31a465a50a8d3796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 17 May 2024 22:22:08 +0200 Subject: [PATCH 15/17] Improve Android build script output, improve colors Abort the Android CMake build immediately if any of the command line arguments is not specified, instead of assuming default values. Add more log messages for different build steps to improve progress reporting and improve the existing log messages. Improve and fix colors of log messages. Previously, some log message colors were not terminated properly, causing the output color of subsequent commands to change. Avoid some error messages when the build script is executed for the first time, i.e. when cleanup of the previous build is not necessary because the files do not exist yet. Make some related variable names more readable by removing the unnecessary underscore and `DEFAULT` prefixes. --- scripts/android/cmake_android.sh | 192 ++++++++++++++++--------------- scripts/android/files/build.sh | 81 +++++++------ 2 files changed, 143 insertions(+), 130 deletions(-) diff --git a/scripts/android/cmake_android.sh b/scripts/android/cmake_android.sh index 976ca87b6..8d1842200 100755 --- a/scripts/android/cmake_android.sh +++ b/scripts/android/cmake_android.sh @@ -12,129 +12,135 @@ export ANDROID_NDK_VERSION # ANDROID_NDK_HOME must be exported for cargo-ndk export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/$ANDROID_NDK_VERSION" -_DEFAULT_ANDROID_BUILD=x86 -_DEFAULT_GAME_NAME=DDNet -_DEFAULT_PACKAGE_NAME=org.ddnet.client -_DEFAULT_BUILD_TYPE=Debug -_DEFAULT_BUILD_FOLDER=build-android -_ANDROID_API_LEVEL=34 +ANDROID_API_LEVEL=34 +ANDROID_SUB_BUILD_DIR=build_arch -_ANDROID_SUB_BUILD_DIR=build_arch +COLOR_RED="\e[1;31m" +COLOR_YELLOW="\e[1;33m" +COLOR_CYAN="\e[1;36m" +COLOR_RESET="\e[0m" -_SHOW_USAGE_INFO=0 +SHOW_USAGE_INFO=0 if [ -z ${1+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass android build type, using default: ${_DEFAULT_ANDROID_BUILD}" - _SHOW_USAGE_INFO=1 + SHOW_USAGE_INFO=1 + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass Android build type" else - _DEFAULT_ANDROID_BUILD=$1 + ANDROID_BUILD=$1 + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Android build type: ${ANDROID_BUILD}" fi if [ -z ${2+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass game name, using default: ${_DEFAULT_GAME_NAME}" - _SHOW_USAGE_INFO=1 + SHOW_USAGE_INFO=1 + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass game name" else - _DEFAULT_GAME_NAME=$2 + GAME_NAME=$2 + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Game name: ${GAME_NAME}" fi if [ -z ${3+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass package name, using default: ${_DEFAULT_PACKAGE_NAME}" - _SHOW_USAGE_INFO=1 + SHOW_USAGE_INFO=1 + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass package name" else - _DEFAULT_PACKAGE_NAME=$3 + PACKAGE_NAME=$3 + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Package name: ${PACKAGE_NAME}" fi if [ -z ${4+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass build type, using default: ${_DEFAULT_BUILD_TYPE}" - _SHOW_USAGE_INFO=1 + SHOW_USAGE_INFO=1 + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass build type" else - _DEFAULT_BUILD_TYPE=$4 + BUILD_TYPE=$4 + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Build type: ${BUILD_TYPE}" fi if [ -z ${5+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass build folder, using default: ${_DEFAULT_BUILD_FOLDER}" - _SHOW_USAGE_INFO=1 + SHOW_USAGE_INFO=1 + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass build folder" else - _DEFAULT_BUILD_FOLDER=$5 + BUILD_FOLDER=$5 + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Build folder: ${BUILD_FOLDER}" fi -_ANDROID_JAR_KEY_NAME=~/.android/debug.keystore -_ANDROID_JAR_KEY_PW=android -_ANDROID_JAR_KEY_ALIAS=androiddebugkey +if [ $SHOW_USAGE_INFO == 1 ]; then + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Usage: ./cmake_android.sh " + exit 1 +fi + +# These are the properties of the default Android debug key. The debug key will +# automatically be created during the Gradle build if it does not exist already, +# so you don't need to create it yourself. +DEFAULT_KEY_NAME=~/.android/debug.keystore +DEFAULT_KEY_PW=android +DEFAULT_KEY_ALIAS=androiddebugkey if [ -z ${TW_KEY_NAME+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass a key for the jar signer, using default: ${_ANDROID_JAR_KEY_NAME}" + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Did not pass a key path for the APK signer, using default: ${DEFAULT_KEY_NAME}" else - _ANDROID_JAR_KEY_NAME=$TW_KEY_NAME + DEFAULT_KEY_NAME=$TW_KEY_NAME fi if [ -z ${TW_KEY_PW+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass a key pw for the jar signer, using default: ${_ANDROID_JAR_KEY_PW}" + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Did not pass a key password for the APK signer, using default: ${DEFAULT_KEY_PW}" else - _ANDROID_JAR_KEY_PW=$TW_KEY_PW + DEFAULT_KEY_PW=$TW_KEY_PW fi if [ -z ${TW_KEY_ALIAS+x} ]; then - printf "\e[31m%s\e[30m\n" "Did not pass a key alias for the jar signer, using default: ${_ANDROID_JAR_KEY_ALIAS}" + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Did not pass a key alias for the APK signer, using default: ${DEFAULT_KEY_ALIAS}" else - _ANDROID_JAR_KEY_ALIAS=$TW_KEY_ALIAS + DEFAULT_KEY_ALIAS=$TW_KEY_ALIAS fi -export TW_KEY_NAME="${_ANDROID_JAR_KEY_NAME}" -export TW_KEY_PW=$_ANDROID_JAR_KEY_PW -export TW_KEY_ALIAS=$_ANDROID_JAR_KEY_ALIAS +export TW_KEY_NAME="${DEFAULT_KEY_NAME}" +export TW_KEY_PW=$DEFAULT_KEY_PW +export TW_KEY_ALIAS=$DEFAULT_KEY_ALIAS -_ANDROID_VERSION_CODE=1 +ANDROID_VERSION_CODE=1 if [ -z ${TW_VERSION_CODE+x} ]; then - _ANDROID_VERSION_CODE=$(grep '#define DDNET_VERSION_NUMBER' src/game/version.h | awk '{print $3}') - if [ -z ${_ANDROID_VERSION_CODE+x} ]; then - _ANDROID_VERSION_CODE=1 + ANDROID_VERSION_CODE=$(grep '#define DDNET_VERSION_NUMBER' src/game/version.h | awk '{print $3}') + if [ -z ${ANDROID_VERSION_CODE+x} ]; then + ANDROID_VERSION_CODE=1 fi - printf "\e[31m%s\e[30m\n" "Did not pass a version code, using default: ${_ANDROID_VERSION_CODE}" + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Did not pass a version code, using default: ${ANDROID_VERSION_CODE}" else - _ANDROID_VERSION_CODE=$TW_VERSION_CODE + ANDROID_VERSION_CODE=$TW_VERSION_CODE fi -export TW_VERSION_CODE=$_ANDROID_VERSION_CODE +export TW_VERSION_CODE=$ANDROID_VERSION_CODE -_ANDROID_VERSION_NAME="1.0" +ANDROID_VERSION_NAME="1.0" if [ -z ${TW_VERSION_NAME+x} ]; then - _ANDROID_VERSION_NAME="$(grep '#define GAME_RELEASE_VERSION' src/game/version.h | awk '{print $3}' | tr -d '"')" - if [ -z ${_ANDROID_VERSION_NAME+x} ]; then - _ANDROID_VERSION_NAME="1.0" + ANDROID_VERSION_NAME="$(grep '#define GAME_RELEASE_VERSION' src/game/version.h | awk '{print $3}' | tr -d '"')" + if [ -z ${ANDROID_VERSION_NAME+x} ]; then + ANDROID_VERSION_NAME="1.0" fi - printf "\e[31m%s\e[30m\n" "Did not pass a version name, using default: ${_ANDROID_VERSION_NAME}" + printf "${COLOR_YELLOW}%s${COLOR_RESET}\n" "Did not pass a version name, using default: ${ANDROID_VERSION_NAME}" else - _ANDROID_VERSION_NAME=$TW_VERSION_NAME + ANDROID_VERSION_NAME=$TW_VERSION_NAME fi -export TW_VERSION_NAME=$_ANDROID_VERSION_NAME +export TW_VERSION_NAME=$ANDROID_VERSION_NAME -printf "\e[31m%s\e[1m\n" "Building with setting, for arch: ${_DEFAULT_ANDROID_BUILD}, with build type: ${_DEFAULT_BUILD_TYPE}, with name: ${_DEFAULT_GAME_NAME} (${_DEFAULT_PACKAGE_NAME})" - -if [ $_SHOW_USAGE_INFO == 1 ]; then - printf "\e[31m%s\e[1m\n" "Usage: ./cmake_android.sh " -fi - -printf "\e[33mBuilding cmake\e[0m\n" +printf "${COLOR_CYAN}%s${COLOR_RESET}\n" "Building cmake..." function build_for_type() { cmake \ -H. \ -G "Ninja" \ -DPREFER_BUNDLED_LIBS=ON \ - -DCMAKE_BUILD_TYPE="${_DEFAULT_BUILD_TYPE}" \ - -DANDROID_PLATFORM="android-${_ANDROID_API_LEVEL}" \ + -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ + -DANDROID_PLATFORM="android-${ANDROID_API_LEVEL}" \ -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ -DANDROID_NDK="$ANDROID_NDK_HOME" \ -DANDROID_ABI="${2}" \ -DANDROID_ARM_NEON=TRUE \ -DCMAKE_ANDROID_NDK="$ANDROID_NDK_HOME" \ -DCMAKE_SYSTEM_NAME=Android \ - -DCMAKE_SYSTEM_VERSION="$_ANDROID_API_LEVEL" \ + -DCMAKE_SYSTEM_VERSION="$ANDROID_API_LEVEL" \ -DCMAKE_ANDROID_ARCH_ABI="${2}" \ -DCARGO_NDK_TARGET="${3}" \ - -DCARGO_NDK_API="$_ANDROID_API_LEVEL" \ + -DCARGO_NDK_API="$ANDROID_API_LEVEL" \ -DDDNET_TEST_NO_LINK=ON \ - -B"${_DEFAULT_BUILD_FOLDER}/$_ANDROID_SUB_BUILD_DIR/$1" \ + -B"${BUILD_FOLDER}/$ANDROID_SUB_BUILD_DIR/$1" \ -DSERVER=OFF \ -DTOOLS=OFF \ -DDEV=TRUE \ @@ -142,60 +148,60 @@ function build_for_type() { -DVULKAN=ON \ -DVIDEORECORDER=OFF ( - cd "${_DEFAULT_BUILD_FOLDER}/$_ANDROID_SUB_BUILD_DIR/$1" || exit 1 + cd "${BUILD_FOLDER}/$ANDROID_SUB_BUILD_DIR/$1" || exit 1 cmake --build . --target game-client ) } -mkdir "${_DEFAULT_BUILD_FOLDER}" +mkdir -p "${BUILD_FOLDER}" -if [[ "${_DEFAULT_ANDROID_BUILD}" == "arm" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "arm" || "${ANDROID_BUILD}" == "all" ]]; then build_for_type arm armeabi-v7a armv7-linux-androideabi & PID_BUILD_ARM=$! fi -if [[ "${_DEFAULT_ANDROID_BUILD}" == "arm64" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "arm64" || "${ANDROID_BUILD}" == "all" ]]; then build_for_type arm64 arm64-v8a aarch64-linux-android & PID_BUILD_ARM64=$! fi -if [[ "${_DEFAULT_ANDROID_BUILD}" == "x86" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "x86" || "${ANDROID_BUILD}" == "all" ]]; then build_for_type x86 x86 i686-linux-android & PID_BUILD_X86=$! fi -if [[ "${_DEFAULT_ANDROID_BUILD}" == "x86_64" || "${_DEFAULT_ANDROID_BUILD}" == "x64" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "x86_64" || "${ANDROID_BUILD}" == "x64" || "${ANDROID_BUILD}" == "all" ]]; then build_for_type x86_64 x86_64 x86_64-linux-android & PID_BUILD_X86_64=$! fi if [ -n "$PID_BUILD_ARM" ] && ! wait "$PID_BUILD_ARM"; then - printf "\e[31m%s\e[30m\n" "Building for arm failed" + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Building for arm failed" exit 1 fi if [ -n "$PID_BUILD_ARM64" ] && ! wait "$PID_BUILD_ARM64"; then - printf "\e[31m%s\e[30m\n" "Building for arm64 failed" + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Building for arm64 failed" exit 1 fi if [ -n "$PID_BUILD_X86" ] && ! wait "$PID_BUILD_X86"; then - printf "\e[31m%s\e[30m\n" "Building for x86 failed" + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Building for x86 failed" exit 1 fi if [ -n "$PID_BUILD_X86_64" ] && ! wait "$PID_BUILD_X86_64"; then - printf "\e[31m%s\e[30m\n" "Building for x86_64 failed" + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Building for x86_64 failed" exit 1 fi -printf "\e[36mPreparing gradle build\n" +printf "${COLOR_CYAN}%s${COLOR_RESET}\n" "Copying project files..." -cd "${_DEFAULT_BUILD_FOLDER}" || exit 1 +cd "${BUILD_FOLDER}" || exit 1 mkdir -p src/main mkdir -p src/main/res/values mkdir -p src/main/res/mipmap function copy_dummy_files() { - rm ./"$2" + rm -f ./"$2" cp ../"$1" "$2" } @@ -211,39 +217,43 @@ copy_dummy_files scripts/android/files/res/values/strings.xml src/main/res/value copy_dummy_files other/icons/DDNet_256x256x32.png src/main/res/mipmap/ic_launcher.png copy_dummy_files other/icons/DDNet_256x256x32.png src/main/res/mipmap/ic_launcher_round.png +printf "${COLOR_CYAN}%s${COLOR_RESET}\n" "Copying libraries..." + function copy_libs() { mkdir -p "lib/$2" - cp "$_ANDROID_SUB_BUILD_DIR/$1/libDDNet.so" "lib/$2" || exit 1 + cp "$ANDROID_SUB_BUILD_DIR/$1/libDDNet.so" "lib/$2" || exit 1 } -if [[ "${_DEFAULT_ANDROID_BUILD}" == "arm" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "arm" || "${ANDROID_BUILD}" == "all" ]]; then copy_libs arm armeabi-v7a fi -if [[ "${_DEFAULT_ANDROID_BUILD}" == "arm64" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "arm64" || "${ANDROID_BUILD}" == "all" ]]; then copy_libs arm64 arm64-v8a fi -if [[ "${_DEFAULT_ANDROID_BUILD}" == "x86" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "x86" || "${ANDROID_BUILD}" == "all" ]]; then copy_libs x86 x86 fi -if [[ "${_DEFAULT_ANDROID_BUILD}" == "x86_64" || "${_DEFAULT_ANDROID_BUILD}" == "x64" || "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then +if [[ "${ANDROID_BUILD}" == "x86_64" || "${ANDROID_BUILD}" == "x64" || "${ANDROID_BUILD}" == "all" ]]; then copy_libs x86_64 x86_64 fi -_DEFAULT_ANDROID_BUILD_DUMMY=$_DEFAULT_ANDROID_BUILD -if [[ "${_DEFAULT_ANDROID_BUILD}" == "all" ]]; then - _DEFAULT_ANDROID_BUILD_DUMMY=arm +ANDROID_BUILD_DUMMY=$ANDROID_BUILD +if [[ "${ANDROID_BUILD}" == "all" ]]; then + ANDROID_BUILD_DUMMY=arm fi +printf "${COLOR_CYAN}%s${COLOR_RESET}\n" "Copying data folder..." mkdir -p assets/asset_integrity_files -cp -R "$_ANDROID_SUB_BUILD_DIR/$_DEFAULT_ANDROID_BUILD_DUMMY/data" ./assets/asset_integrity_files +cp -R "$ANDROID_SUB_BUILD_DIR/$ANDROID_BUILD_DUMMY/data" ./assets/asset_integrity_files -curl --remote-name --time-cond cacert.pem https://curl.se/ca/cacert.pem -cp ./cacert.pem ./assets/asset_integrity_files/data/cacert.pem +printf "${COLOR_CYAN}%s${COLOR_RESET}\n" "Downloading certificate..." +curl -s -S --remote-name --time-cond cacert.pem https://curl.se/ca/cacert.pem +cp ./cacert.pem ./assets/asset_integrity_files/data/cacert.pem || exit 1 -# create integrity file for extracting assets +printf "${COLOR_CYAN}%s${COLOR_RESET}\n" "Creating integrity index file..." ( cd assets/asset_integrity_files || exit 1 @@ -256,23 +266,21 @@ cp ./cacert.pem ./assets/asset_integrity_files/data/cacert.pem full_hash="$(sha256sum "$tmpfile" | cut -d' ' -f 1)" - rm "integrity.txt" + rm -f "integrity.txt" { echo "$full_hash" cat "$tmpfile" } > "integrity.txt" ) -printf "\e[0m" +printf "${COLOR_CYAN}%s${COLOR_RESET}\n" "Preparing gradle build..." -echo "Building..." - -rm -R src/main/java/org +rm -R -f src/main/java/org mkdir -p src/main/java cp -R ../scripts/android/files/java/org src/main/java/ cp -R ../ddnet-libs/sdl/java/org src/main/java/ # shellcheck disable=SC1091 -source ./build.sh "$_DEFAULT_GAME_NAME" "$_DEFAULT_PACKAGE_NAME" "$_DEFAULT_BUILD_TYPE" +source ./build.sh "$GAME_NAME" "$PACKAGE_NAME" "$BUILD_TYPE" cd .. diff --git a/scripts/android/files/build.sh b/scripts/android/files/build.sh index ef6c2f3cf..f2528b091 100644 --- a/scripts/android/files/build.sh +++ b/scripts/android/files/build.sh @@ -1,38 +1,41 @@ #!/bin/bash -[ "$1" == "" ] && { - printf '\e[31mDid not pass APK name to build script\e[30m\n' - exit 1 -} +COLOR_RED="\e[1;31m" +COLOR_RESET="\e[0m" -[ "$2" == "" ] && { - printf '\e[31mDid not pass package name to build script\e[30m\n' - exit 1 -} - -[ "$3" == "" ] && { - printf '\e[31mDid not pass build type to build script\e[30m\n' - exit 1 -} - -_APK_BASENAME="$1" -_APK_PACKAGE_NAME="$2" -_APK_BUILD_TYPE="$3" - -if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then - _RELEASE_TYPE_NAME=debug -elif [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then - _RELEASE_TYPE_NAME=release -else - printf '\e[31mDid not pass build type to build script: Debug, Release\e[30m\n' +if [ -z ${1+x} ]; then + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass APK name to build script" exit 1 fi -_APK_PACKAGE_FOLDER=$(echo "$_APK_PACKAGE_NAME" | sed 's/\./\//g') +if [ -z ${2+x} ]; then + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass package name to build script" + exit 1 +fi -sed -i "s/DDNet/${_APK_BASENAME}/g" settings.gradle +if [ -z ${3+x} ]; then + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass build type to build script: Debug, Release" + exit 1 +fi -sed -i "s/org.ddnet.client/${_APK_PACKAGE_NAME}/g" build.gradle +APK_BASENAME="$1" +APK_PACKAGE_NAME="$2" +APK_BUILD_TYPE="$3" + +if [[ "${APK_BUILD_TYPE}" == "Debug" ]]; then + RELEASE_TYPE_NAME=debug +elif [[ "${APK_BUILD_TYPE}" == "Release" ]]; then + RELEASE_TYPE_NAME=release +else + printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass build type to build script: Debug, Release" + exit 1 +fi + +APK_PACKAGE_FOLDER=$(echo "$APK_PACKAGE_NAME" | sed 's/\./\//g') + +sed -i "s/DDNet/${APK_BASENAME}/g" settings.gradle + +sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" build.gradle TW_KEY_NAME_ESCAPED=$(echo "$TW_KEY_NAME" | sed 's/\//\\\//g') TW_KEY_PW_ESCAPED=$(echo "$TW_KEY_PW" | sed 's/\//\\\//g') @@ -46,20 +49,22 @@ sed -i "s/TW_NDK_VERSION/${ANDROID_NDK_VERSION}/g" build.gradle sed -i "s/TW_VERSION_CODE/${TW_VERSION_CODE}/g" build.gradle sed -i "s/TW_VERSION_NAME/${TW_VERSION_NAME}/g" build.gradle -sed -i "s/DDNet/${_APK_BASENAME}/g" src/main/res/values/strings.xml +sed -i "s/DDNet/${APK_BASENAME}/g" src/main/res/values/strings.xml -sed -i "s/\"DDNet\"/\"${_APK_BASENAME}\"/g" src/main/AndroidManifest.xml -sed -i "s/org.ddnet.client/${_APK_PACKAGE_NAME}/g" src/main/AndroidManifest.xml +sed -i "s/\"DDNet\"/\"${APK_BASENAME}\"/g" src/main/AndroidManifest.xml +sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" src/main/AndroidManifest.xml -mv src/main/java/org/ddnet/client src/main/java/"${_APK_PACKAGE_FOLDER}" +if [ "${APK_PACKAGE_FOLDER}" != "org/ddnet/client" ]; then + mv src/main/java/org/ddnet/client src/main/java/"${APK_PACKAGE_FOLDER}" +fi -sed -i "s/org.ddnet.client/${_APK_PACKAGE_NAME}/g" src/main/java/"${_APK_PACKAGE_FOLDER}"/NativeMain.java -sed -i "s/org.ddnet.client/${_APK_PACKAGE_NAME}/g" proguard-rules.pro +sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" src/main/java/"${APK_PACKAGE_FOLDER}"/NativeMain.java +sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" proguard-rules.pro # disable hid manager for now sed -i "s/mHIDDeviceManager = HIDDeviceManager.acquire(this);/mHIDDeviceManager=null;/g" src/main/java/org/libsdl/app/SDLActivity.java -if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then +if [[ "${APK_BUILD_TYPE}" == "Debug" ]]; then sed -i "s/android.enableR8.fullMode=true/android.enableR8.fullMode=false/g" gradle.properties fi @@ -67,16 +72,16 @@ function build_gradle() { java "-Dorg.gradle.appname=Gradle" -classpath gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain --warning-mode all "$1" } -if [[ "${_APK_BUILD_TYPE}" == "Debug" ]]; then +if [[ "${APK_BUILD_TYPE}" == "Debug" ]]; then build_gradle builddebug build_gradle assembleDebug else build_gradle buildrelease build_gradle assembleRelease fi -cp build/outputs/apk/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME".apk "$_APK_BASENAME".apk +cp build/outputs/apk/"$RELEASE_TYPE_NAME"/"$APK_BASENAME"-"$RELEASE_TYPE_NAME".apk "$APK_BASENAME".apk -if [[ "${_APK_BUILD_TYPE}" == "Release" ]]; then +if [[ "${APK_BUILD_TYPE}" == "Release" ]]; then build_gradle bundleRelease - cp build/outputs/bundle/"$_RELEASE_TYPE_NAME"/"$_APK_BASENAME"-"$_RELEASE_TYPE_NAME".aab "$_APK_BASENAME".aab + cp build/outputs/bundle/"$RELEASE_TYPE_NAME"/"$APK_BASENAME"-"$RELEASE_TYPE_NAME".aab "$APK_BASENAME".aab fi From 63710a18a4bf59407059f4393e3f2018e3682844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 23 May 2024 21:28:38 +0200 Subject: [PATCH 16/17] Preserve filenames and line numbers in ProGuard for debugging --- scripts/android/files/proguard-rules.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/android/files/proguard-rules.pro b/scripts/android/files/proguard-rules.pro index ebf7b3d1f..53c691af5 100644 --- a/scripts/android/files/proguard-rules.pro +++ b/scripts/android/files/proguard-rules.pro @@ -14,7 +14,7 @@ # Uncomment this to preserve the line number information for # debugging stack traces. -#-keepattributes SourceFile,LineNumberTable +-keepattributes SourceFile,LineNumberTable -keepclassmembers, allowoptimization public class org.ddnet.client.NativeMain { *; From 1dfed5434ebc2479b726033e85aa2887d852edee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 23 May 2024 21:55:57 +0200 Subject: [PATCH 17/17] Lower minimum SDK to 19, remove unnecessary Gradle dependencies SDK 19 is the lowest API level support by SDL2 because it is the lowest API level supported by the latest NDK toolchain. According to https://www.composables.com/tools/distribution-chart this should cover virtually all Android devices. The dependencies on Kotlin and various `androidx`-Packages were entirely unnecessary and can be removed. --- scripts/android/files/build.gradle | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/scripts/android/files/build.gradle b/scripts/android/files/build.gradle index e9df90729..1025f955e 100644 --- a/scripts/android/files/build.gradle +++ b/scripts/android/files/build.gradle @@ -1,17 +1,12 @@ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' - buildscript { - ext.kotlin_version = '+' repositories { google() mavenCentral() } - dependencies { classpath 'com.android.tools.build:gradle:8.3.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -27,7 +22,7 @@ android { defaultConfig { applicationId "org.ddnet.client" namespace("org.ddnet.client") - minSdkVersion 24 + minSdkVersion 19 targetSdkVersion 34 versionCode TW_VERSION_CODE versionName "TW_VERSION_NAME" @@ -61,10 +56,8 @@ android { main { assets.srcDirs = ['assets'] jniLibs.srcDirs = ['lib'] - //TW_ENABLE_RESOURCESresources.srcDirs = ['resources'] } } - lintOptions { abortOnError false } @@ -81,10 +74,3 @@ allprojects { } } } - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.core:core-ktx:1.3.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' -}