From d1ee71a6344d5be5231d4a1ae089589337a7bcd2 Mon Sep 17 00:00:00 2001 From: Benjamin Deroche Date: Mon, 9 May 2022 12:15:24 +0200 Subject: [PATCH] Problem: Android build scripts does not work with latest NDK versions Solution: Update the build scripts to work with NDK versions r23 and r24 --- README.md | 2 +- builds/android/README.md | 6 ++--- builds/android/android_build_helper.sh | 31 ++++++++++++++++++++------ builds/android/build.sh | 7 +++--- builds/android/ci_build.sh | 6 ++--- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7760ce0e..e9b9bc61 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ of platforms, where libzmq has been successfully compiled on. | OS and version | Architecture | Compiler and version | Build system | Remarks | |----------------------------------------|-------------------------|-------------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------| -| Android NDK r20 | arm, arm64, x86, x86_64 | llvm (see NDK) | autotools | DRAFT | +| Android NDK r24 | arm, arm64, x86, x86_64 | llvm (see NDK) | autotools | DRAFT | | Ubuntu 14.04.5 LTS (trusty) | amd64 | clang 5.0.0 | autotools | STABLE, extras: GSSAPI, PGM, NORM, C++98 mode only | | Ubuntu 14.04.5 LTS (trusty) | amd64 | gcc 4.8.4 | autotools | STABLE, DRAFT, extras: GSSAPI, PGM, NORM, TIPC, IPV6, also POLLER=poll, POLLER=select, also valgrind and address sanitizer executions | | Ubuntu 14.04.5 LTS (trusty) | amd64 | gcc 4.8.4 | CMake 3.12.2 | STABLE | diff --git a/builds/android/README.md b/builds/android/README.md index ddc1abeb..83c9a72e 100644 --- a/builds/android/README.md +++ b/builds/android/README.md @@ -5,12 +5,12 @@ You need the Android Native Development Kit (NDK) installed. See [here](https://developer.android.com/ndk) to download it. -This project is tested against Android NDK version r21d. +This project is tested against Android NDK version r24. -If you installed version r21e all you have to do is to expose the NDK root +If you installed version r24 all you have to do is to expose the NDK root directory as environment variable, e.g: - export ANDROID_NDK_ROOT=$HOME/android-ndk-r21e + export ANDROID_NDK_ROOT=$HOME/android-ndk-r24 If you installed another version you have to expose the NDK root directory as well as the NDK version, e.g: diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index 81c2557a..72720cd9 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -112,12 +112,12 @@ function android_build_env { if [ -z "$ANDROID_NDK_ROOT" ]; then ANDROID_BUILD_FAIL+=("Please set the ANDROID_NDK_ROOT environment variable") - ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r20\")") + ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r24\")") fi if [ -z "$TOOLCHAIN_PATH" ]; then ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_PATH environment variable") - ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin\")") + ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r24/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin\")") fi if [ -z "$TOOLCHAIN_HOST" ]; then @@ -181,10 +181,22 @@ function _android_build_opts_process_binaries { else local LD="${TOOLCHAIN_PATH}/ld" fi - local AS="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-as" - local AR="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar" - local RANLIB="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ranlib" - local STRIP="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-strip" + # Since NDK r24 this binary was removed due to LLVM being now the default + if [ ! -x "${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-as" ]; then + local AS="${TOOLCHAIN_PATH}/llvm-as" + else + local AS="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-as" + fi + # Since NDK r23 those binaries were removed due to LLVM being now the default + if [ ! -x "${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar" ]; then + local AR="${TOOLCHAIN_PATH}/llvm-ar" + local RANLIB="${TOOLCHAIN_PATH}/llvm-ranlib" + local STRIP="${TOOLCHAIN_PATH}/llvm-strip" + else + local AR="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar" + local RANLIB="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ranlib" + local STRIP="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-strip" + fi if [ ! -x "${CC}" ]; then ANDROID_BUILD_FAIL+=("The CC binary does not exist or is not executable") @@ -239,7 +251,12 @@ function android_build_opts { _android_build_opts_process_binaries - local LIBS="-lc -lgcc -ldl -lm -llog -lc++_shared" + # Since NDK r23 we don't need -lgcc due to LLVM being now the default + if [ ! -x "${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar" ]; then + local LIBS="-lc -ldl -lm -llog -lc++_shared" + else + local LIBS="-lc -lgcc -ldl -lm -llog -lc++_shared" + fi local LDFLAGS="-L${ANDROID_BUILD_PREFIX}/lib" LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_ABI}" CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE" diff --git a/builds/android/build.sh b/builds/android/build.sh index 667df7cc..d7898fbb 100755 --- a/builds/android/build.sh +++ b/builds/android/build.sh @@ -34,10 +34,9 @@ case $(uname | tr '[:upper:]' '[:lower:]') in esac # Set default values used in ci builds - -export NDK_VERSION=${NDK_VERSION:-android-ndk-r22b} -# With NDK r21e, the minimum SDK version range is [16, 29]. -# SDK version 21 is the minimum version for 64-bit builds. +export NDK_VERSION=${NDK_VERSION:-android-ndk-r24} +# With NDK r22b, the minimum SDK version range is [16, 31]. +# Since NDK r24, the minimum SDK version range is [19, 31]. export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21} # Set up android build environment and set ANDROID_BUILD_OPTS array diff --git a/builds/android/ci_build.sh b/builds/android/ci_build.sh index 1ffa771d..e6ef08e7 100755 --- a/builds/android/ci_build.sh +++ b/builds/android/ci_build.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash -export NDK_VERSION=android-ndk-r22b +export NDK_VERSION=android-ndk-r24 export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}" case $(uname | tr '[:upper:]' '[:lower:]') in linux*) - HOST_PLATFORM=linux-x86_64 + HOST_PLATFORM=linux ;; darwin*) - HOST_PLATFORM=darwin-x86_64 + HOST_PLATFORM=darwin ;; *) echo "Unsupported platform"