1
0

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 <mail@mathias.is>
This commit is contained in:
Alexander Harkness 2020-01-02 01:54:40 +00:00 committed by Mat
parent 57a248bfbf
commit bf10b56638
4 changed files with 23 additions and 27 deletions

3
android/.gitignore vendored
View File

@ -1 +1,2 @@
/Cuberite/ /Cuberite/
Server

View File

@ -22,7 +22,7 @@ include_directories(SYSTEM
) )
# Disable some compiler warnings (the lazy way out) # 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 # Build the rest of the server
add_subdirectory(../ Cuberite) add_subdirectory(../ Cuberite)

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
set -e
# This script cross-compiles cuberite for the android platform. It uses # This script cross-compiles cuberite for the android platform. It uses
# the following enviroment variables # the following enviroment variables
# CMAKE: Should be the path to a cmake executable of version 3.7+ # CMAKE: Should be the path to a cmake executable of version 3.7+
@ -13,16 +15,16 @@ function usage() {
} }
BASEDIR="$(realpath $(dirname $0))" BASEDIR="$(realpath $(dirname $0))"
BUILDDIR="$BASEDIR/../android-build"
SELF="./$(basename $0)" SELF="./$(basename $0)"
# Clean doesn't need CMAKE and NDK, so it's handled here # Clean doesn't need CMAKE and NDK, so it's handled here
if [ "$1" == "clean" ]; then if [ "$1" == "clean" ]; then
cd $BASEDIR rm -rf $BUILDDIR
rm -rf ../android-build/
exit 0 exit 0
fi fi
if [ -z "$CMAKE" -o -z "$NDK" ];then if [ -z "$CMAKE" -o -z "$NDK" ]; then
usage; usage;
fi fi
@ -41,28 +43,17 @@ fi
cd $BASEDIR cd $BASEDIR
case "$1" in case "$1" in
armeabi)
APILEVEL=16
;;
armeabi-v7a) armeabi-v7a)
APILEVEL=16 APILEVEL=14
;; ;;
arm64-v8a) arm64-v8a)
APILEVEL=21 APILEVEL=21
;; ;;
mips)
APILEVEL=16
;;
mips64)
APILEVEL=21
;;
x86) x86)
APILEVEL=16 APILEVEL=14
;; ;;
x86_64) x86_64)
@ -71,22 +62,22 @@ case "$1" in
all) all)
echo "Packing server.zip ..." echo "Packing server.zip ..."
rm -rf Server
mkdir -p Server mkdir -p Server
cd $BASEDIR/../Server cd $BASEDIR/../Server
zip -r $BASEDIR/Server/server.zip * 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 ..." && \ echo "Doing ... $arch ..." && \
cd $BASEDIR && \ cd $BASEDIR && \
"$SELF" clean && \ "$SELF" clean && \
"$SELF" "$arch" && \ "$SELF" "$arch" && \
cd Server && \ cd $BUILDDIR/Server && \
zip "$arch".zip Cuberite && \ zip $BASEDIR/Server/"$arch".zip Cuberite
rm Cuberite
done done
cd $BASEDIR/Server 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 ..." && \ echo "Generating sha1 sum for ... $file ..." && \
sha1sum "$file" > "$file".sha1 sha1sum "$file" > "$file".sha1
done done
@ -100,7 +91,11 @@ case "$1" in
;; ;;
esac esac
mkdir -p $BASEDIR/../android-build mkdir -p $BUILDDIR
cd $BASEDIR/../android-build cd $BUILDDIR
"$CMAKE" $BASEDIR/../android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION="$APILEVEL" -DCMAKE_BUILD_TYPE="$TYPE" -DCMAKE_ANDROID_ARCH_ABI="$1" -DCMAKE_ANDROID_NDK="$NDK" "$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" make -j "$THREADS"

View File

@ -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(): // 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)); char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
if (res != nullptr) if (res != nullptr)