From d536bceed6a6f5e30b3a973c793cfe284640bf7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 8 Sep 2024 17:29:32 +0200 Subject: [PATCH] Fix minimum Android API version and linking errors The minimum supported API version must be specified when building the native libraries, otherwise this may cause linking errors when launching the app. The minimum API level is increased to 24 (Android 7.0, covering 97.2% of usages) because: - Vulkan is only available from API 24+ on ARM64 and x64. - curl only compiles with API 23+. - The NDK version we use supports only API 21+. Ensure that the C++/Linker flags are set when building Android libraries, which was causing errors due to `-fPIC` not being set for all libraries. --- scripts/android/cmake_android.sh | 3 ++- scripts/android/files/build.gradle | 2 +- scripts/compile_libs/cmake_lib_compile.sh | 2 ++ scripts/compile_libs/gen_libs.sh | 11 ++++++----- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/android/cmake_android.sh b/scripts/android/cmake_android.sh index 2ceeecb47..643d016a5 100755 --- a/scripts/android/cmake_android.sh +++ b/scripts/android/cmake_android.sh @@ -10,7 +10,8 @@ ANDROID_NDK_VERSION="${ANDROID_NDK_VERSION:2}" # ANDROID_NDK_HOME must be exported for cargo-ndk export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/$ANDROID_NDK_VERSION" -ANDROID_API_LEVEL=34 +# ANDROID_API_LEVEL must specify the _minimum_ supported SDK version, otherwise this will cause linking errors at launch +ANDROID_API_LEVEL=24 ANDROID_SUB_BUILD_DIR=build_arch COLOR_RED="\e[1;31m" diff --git a/scripts/android/files/build.gradle b/scripts/android/files/build.gradle index e0090e7d0..cc1a53904 100644 --- a/scripts/android/files/build.gradle +++ b/scripts/android/files/build.gradle @@ -21,7 +21,7 @@ android { defaultConfig { applicationId "org.ddnet.client" namespace("org.ddnet.client") - minSdkVersion 19 + minSdkVersion 24 targetSdkVersion 34 versionCode TW_VERSION_CODE versionName "TW_VERSION_NAME" diff --git a/scripts/compile_libs/cmake_lib_compile.sh b/scripts/compile_libs/cmake_lib_compile.sh index 775584e11..72c3ee741 100755 --- a/scripts/compile_libs/cmake_lib_compile.sh +++ b/scripts/compile_libs/cmake_lib_compile.sh @@ -29,6 +29,8 @@ function compile_source_android() { -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_SYSTEM_VERSION="$1" \ -DCMAKE_ANDROID_ARCH_ABI="${3}" \ + -DCMAKE_C_FLAGS="$COMPILEFLAGS" -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" \ -B"$2" \ -DBUILD_SHARED_LIBS=OFF \ -DHIDAPI_SKIP_LIBUSB=TRUE \ diff --git a/scripts/compile_libs/gen_libs.sh b/scripts/compile_libs/gen_libs.sh index e9a6436bc..9ba0a460b 100755 --- a/scripts/compile_libs/gen_libs.sh +++ b/scripts/compile_libs/gen_libs.sh @@ -46,7 +46,8 @@ fi mkdir -p "$1" cd "$1" || exit 1 -_ANDROID_ABI_LEVEL=34 +# ANDROID_API_LEVEL must specify the _minimum_ supported SDK version, otherwise this will cause linking errors at launch +ANDROID_API_LEVEL=24 function build_cmake_lib() { if [ ! -d "${1}" ]; then @@ -59,7 +60,7 @@ function build_cmake_lib() { ( cd "${1}" || exit 1 cp "${CURDIR}"/scripts/compile_libs/cmake_lib_compile.sh cmake_lib_compile.sh - ./cmake_lib_compile.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" + ./cmake_lib_compile.sh "$ANDROID_API_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" ) } @@ -74,7 +75,7 @@ cd compile_libs || exit 1 ( cd openssl || exit 1 cp "${CURDIR}"/scripts/compile_libs/make_lib_openssl.sh make_lib_openssl.sh - ./make_lib_openssl.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" + ./make_lib_openssl.sh "$ANDROID_API_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" ) ) @@ -97,7 +98,7 @@ build_cmake_lib opus https://github.com/xiph/opus ./autogen.sh fi cp "${CURDIR}"/scripts/compile_libs/make_lib_opusfile.sh make_lib_opusfile.sh - ./make_lib_opusfile.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" + ./make_lib_opusfile.sh "$ANDROID_API_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" ) # SQLite, just download and built by hand @@ -109,7 +110,7 @@ fi ( cd sqlite3 || exit 1 cp "${CURDIR}"/scripts/compile_libs/make_lib_sqlite3.sh make_lib_sqlite3.sh - ./make_lib_sqlite3.sh "$_ANDROID_ABI_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" + ./make_lib_sqlite3.sh "$ANDROID_API_LEVEL" "$OS_NAME" "$COMPILEFLAGS" "$LINKFLAGS" ) cd ..