From bf10b566383e67b7a26d1dc80bb3bc613168c1b5 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Thu, 2 Jan 2020 01:54:40 +0000 Subject: Fix android builds (#4432) * Terminate android build script early if any step fails * Remove deprecated android types * Use android NDK cmake support rather than cmake android NDK support as that support is better supported * Android uses GNU strerror_r? * Fix compilation * Rebase * Fix final issues * Drop submodule changes * Revert change * Parentheses * Lower api levels * Don't use GNU strerror_r for Android Co-authored-by: Mat --- android/.gitignore | 3 ++- android/CMakeLists.txt | 2 +- android/compile.sh | 43 +++++++++++++++++++------------------------ src/OSSupport/Errors.cpp | 2 +- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/android/.gitignore b/android/.gitignore index f23a2c19b..1335c1112 100644 --- a/android/.gitignore +++ b/android/.gitignore @@ -1 +1,2 @@ -/Cuberite/ \ No newline at end of file +/Cuberite/ +Server \ No newline at end of file diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 4f863d114..99eada26f 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -22,7 +22,7 @@ include_directories(SYSTEM ) # Disable some compiler warnings (the lazy way out) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-double-promotion") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-double-promotion -Wno-sign-conversion") # Build the rest of the server add_subdirectory(../ Cuberite) diff --git a/android/compile.sh b/android/compile.sh index 78a42d883..8be0e147c 100755 --- a/android/compile.sh +++ b/android/compile.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + # This script cross-compiles cuberite for the android platform. It uses # the following enviroment variables # CMAKE: Should be the path to a cmake executable of version 3.7+ @@ -13,16 +15,16 @@ function usage() { } BASEDIR="$(realpath $(dirname $0))" +BUILDDIR="$BASEDIR/../android-build" SELF="./$(basename $0)" # Clean doesn't need CMAKE and NDK, so it's handled here if [ "$1" == "clean" ]; then - cd $BASEDIR - rm -rf ../android-build/ + rm -rf $BUILDDIR exit 0 fi -if [ -z "$CMAKE" -o -z "$NDK" ];then +if [ -z "$CMAKE" -o -z "$NDK" ]; then usage; fi @@ -41,28 +43,17 @@ fi cd $BASEDIR case "$1" in - armeabi) - APILEVEL=16 - ;; armeabi-v7a) - APILEVEL=16 + APILEVEL=14 ;; arm64-v8a) APILEVEL=21 ;; - mips) - APILEVEL=16 - ;; - - mips64) - APILEVEL=21 - ;; - x86) - APILEVEL=16 + APILEVEL=14 ;; x86_64) @@ -71,22 +62,22 @@ case "$1" in all) echo "Packing server.zip ..." + rm -rf Server mkdir -p Server cd $BASEDIR/../Server zip -r $BASEDIR/Server/server.zip * - for arch in armeabi armeabi-v7a arm64-v8a mips mips64 x86 x86_64; do + for arch in armeabi-v7a arm64-v8a x86 x86_64; do echo "Doing ... $arch ..." && \ cd $BASEDIR && \ "$SELF" clean && \ "$SELF" "$arch" && \ - cd Server && \ - zip "$arch".zip Cuberite && \ - rm Cuberite + cd $BUILDDIR/Server && \ + zip $BASEDIR/Server/"$arch".zip Cuberite done cd $BASEDIR/Server - for file in server.zip armeabi.zip armeabi-v7a.zip arm64-v8a.zip mips.zip mips64.zip x86.zip x86_64.zip; do + for file in server.zip armeabi-v7a.zip arm64-v8a.zip x86.zip x86_64.zip; do echo "Generating sha1 sum for ... $file ..." && \ sha1sum "$file" > "$file".sha1 done @@ -100,7 +91,11 @@ case "$1" in ;; esac -mkdir -p $BASEDIR/../android-build -cd $BASEDIR/../android-build -"$CMAKE" $BASEDIR/../android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION="$APILEVEL" -DCMAKE_BUILD_TYPE="$TYPE" -DCMAKE_ANDROID_ARCH_ABI="$1" -DCMAKE_ANDROID_NDK="$NDK" +mkdir -p $BUILDDIR +cd $BUILDDIR +"$CMAKE" $BASEDIR/../android -DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI="$1" \ + -DANDROID_NATIVE_API_LEVEL="$APILEVEL" \ + -DCMAKE_BUILD_TYPE="$TYPE" + make -j "$THREADS" diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index a6a66c73c..df94d34da 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -22,7 +22,7 @@ AString GetOSErrorString( int a_ErrNo) // According to https://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if defined(__GLIBC__) && defined( _GNU_SOURCE) && !defined(ANDROID) // GNU version of strerror_r() + #if defined(__GLIBC__) && defined( _GNU_SOURCE) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer)); if (res != nullptr) -- cgit v1.2.3