Unverified Commit 91792109 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3827 from sappo/master

Improve android build handling
parents d5bd1642 1fc4f513
This diff is collapsed.
LIBZMQ ANDROID COMPILATION STEPS # Android Build
================================
To launch the docker build:
$ docker build . ## Prerequisites
To launch the android build, you have to first install the android-ndk first in your HOME directory: You need the Android Native Development Kit (NDK) installed. See
[here](https://developer.android.com/ndk) to download it.
$ cd ~ This project is tested against Android NDK version r20.
$ export ANDROID_NDK_VERSION="r10e"
$ wget -q https://dl.google.com/android/ndk/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.bin -O android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.bin
$ #check the hashes before executing this binary
$ md5sum android-ndk-r10e-linux-x86_64.bin
# 19af543b068bdb7f27787c2bc69aba7f android-ndk-r10e-linux-x86_64.bin
$ sha256sum android-ndk-r10e-linux-x86_64.bin
# 102d6723f67ff1384330d12c45854315d6452d6510286f4e5891e00a5a8f1d5a android-ndk-r10e-linux-x86_64.bin
$ chmod +x android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.bin
$ ./android-ndk-r10e-linux-x86_64.bin
$ export ANDROID_NDK_ROOT=${HOME}/android-ndk-r10e
$ export TOOLCHAIN_NAME=arm-linux-androideabi-4.9
$ export TOOLCHAIN_HOST=arm-linux-androideabi
$ export TOOLCHAIN_PATH=${ANDROID_NDK_ROOT}/toolchains/${TOOLCHAIN_NAME}/prebuilt/linux-x86_64/bin
$ export TOOLCHAIN_ARCH=arm
Then you can launch the build: If you installed version r20 all you have to do is to expose the NDK root
directory as environment variable, e.g:
$ cd ~/libzmq/builds/android export ANDROID_NDK_ROOT=$HOME/android-ndk-r20
$ ./build.sh
Cloning into 'libsodium'...
remote: Counting objects: 15246, done.
remote: Compressing objects: 100% (182/182), done.
Receiving objects: 16% (2440/15246)
[...]
A successful build should finish with the following message and give you back your shell prompt: If you installed another version you have to expose the NDK root directory as
well as the NDK version, e.g:
[...] export ANDROID_NDK_ROOT=$HOME/android-ndk-r17c
make[2]: Leaving directory '/tmp/android_build/arm-linux-androideabi-4.9/libzmq' export NDK_VERSION=android-ndk-r17c
make[1]: Leaving directory '/tmp/android_build/arm-linux-androideabi-4.9/libzmq'
libzmq android build succeeded
$
You will then be able to see libzmq.so compiled in the prefix/ directory: To specify the minimum sdk version set the environment variable below:
$ cd ~/libzmq/builds/android/prefix/arm-linux-androideabi-4.9/lib export MIN_SDK_VERSION=21 # Default value if unset
$ ls
libsodium.a libsodium.la libsodium.so libzmq.a libzmq.la libzmq.so pkgconfig
You can then triple check that they are ARM libs: ## Build
$ cd ~/libzmq/builds/android/prefix/arm-linux-androideabi-4.9/lib In the android directory, run:
$ file libzmq.so
libzmq.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/bin/linker, not stripped
./build.sh [ arm | arm64 | x86 | x86_64 ]
COMPILE WITH DOCKERFILE
=======================
To launch the docker build with a tagged image as a result:
$ cd ~/libzmq/builds/android
$ docker build -t libzmq-android:`date +"%y%m%d-%H%M%S"` .
$ docker build -t libzmq-android:latest .
If it is successful, it will end by "libzmq android build succeeded" followed by the ContainerID "e53db616aff4":
[...]
make[2]: Leaving directory `/tmp/android_build/arm-linux-androideabi-4.9/libzmq'
make[1]: Leaving directory `/tmp/android_build/arm-linux-androideabi-4.9/libzmq'
libzmq android build succeeded
---> e53db616aff4
Removing intermediate container 8a5f3e34f3da
Successfully built e53db616aff4
$
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
libzmq-android 151218-101411 e53db616aff4 18 hours ago 5.495 GB
If you want to collect the artifacts on the build, you can specify a directory in your HOME directory, such as "$HOME/libzmq-android-bins" for example:
$ mkdir -pv $HOME/libzmq-android-bins
$ docker run -v $HOME/libzmq-android-bins:/data libzmq-android:latest "cp -v /home/zmq/libzmq/builds/android/prefix/arm-linux-androideabi-4.9/lib/* /data"
...@@ -69,72 +69,80 @@ function android_build_check_fail { ...@@ -69,72 +69,80 @@ function android_build_check_fail {
fi fi
} }
function android_build_arch {
export TOOLCHAIN_PATH="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin"
export TOOLCHAIN_HOST=$1
export TOOLCHAIN_COMP=$2
export TOOLCHAIN_CXXSTL=$3
export TOOLCHAIN_ARCH=$4
}
function android_build_env { function android_build_env {
## ##
# Check that necessary environment variables are set # Check that necessary environment variables are set
if [ -z "$ANDROID_NDK_ROOT" ]; then if [ -z "$ANDROID_NDK_ROOT" ]; then
ANDROID_BUILD_FAIL+=("Please set the ANDROID_NDK_ROOT environment variable") 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-r20\")")
fi fi
if [ -z "$TOOLCHAIN_PATH" ]; then if [ -z "$TOOLCHAIN_PATH" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_PATH environment variable") 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-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin\")")
fi fi
if [ -z "$TOOLCHAIN_HOST" ]; then if [ -z "$TOOLCHAIN_HOST" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_HOST environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_HOST environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"arm-linux-androideabi\")") ANDROID_BUILD_FAIL+=(" (eg. \"arm-linux-androideabi\")")
fi fi
if [ -z "$TOOLCHAIN_COMP" ]; then if [ -z "$TOOLCHAIN_COMP" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_COMP environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_COMP environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armv7a-linux-androideabi\")") ANDROID_BUILD_FAIL+=(" (eg. \"armv7a-linux-androideabi\")")
fi fi
if [ -z "$TOOLCHAIN_CXXSTL" ]; then if [ -z "$TOOLCHAIN_CXXSTL" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_CXXSTL environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_CXXSTL environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7abi\")") ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7abi\")")
fi fi
if [ -z "$TOOLCHAIN_ARCH" ]; then if [ -z "$TOOLCHAIN_ARCH" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_ARCH environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_ARCH environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"arm\")") ANDROID_BUILD_FAIL+=(" (eg. \"arm\")")
fi fi
android_build_check_fail android_build_check_fail
## ##
# Check that directories given by environment variables exist # Check that directories given by environment variables exist
if [ ! -d "$ANDROID_NDK_ROOT" ]; then if [ ! -d "$ANDROID_NDK_ROOT" ]; then
ANDROID_BUILD_FAIL+=("The ANDROID_NDK_ROOT directory does not exist") ANDROID_BUILD_FAIL+=("The ANDROID_NDK_ROOT directory does not exist")
ANDROID_BUILD_FAIL+=(" ${ANDROID_NDK_ROOT}") ANDROID_BUILD_FAIL+=(" ${ANDROID_NDK_ROOT}")
fi fi
if [ ! -d "$TOOLCHAIN_PATH" ]; then if [ ! -d "$TOOLCHAIN_PATH" ]; then
ANDROID_BUILD_FAIL+=("The TOOLCHAIN_PATH directory does not exist") ANDROID_BUILD_FAIL+=("The TOOLCHAIN_PATH directory does not exist")
ANDROID_BUILD_FAIL+=(" ${TOOLCHAIN_PATH}") ANDROID_BUILD_FAIL+=(" ${TOOLCHAIN_PATH}")
fi fi
## ##
# Set up some local variables and check them # Set up some local variables and check them
ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}" ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}"
if [ ! -d "$ANDROID_BUILD_SYSROOT" ]; then if [ ! -d "$ANDROID_BUILD_SYSROOT" ]; then
ANDROID_BUILD_FAIL+=("The ANDROID_BUILD_SYSROOT directory does not exist") ANDROID_BUILD_FAIL+=("The ANDROID_BUILD_SYSROOT directory does not exist")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_SYSROOT}") ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_SYSROOT}")
fi fi
ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_NAME}" ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}"
mkdir -p "$ANDROID_BUILD_PREFIX" || { mkdir -p "$ANDROID_BUILD_PREFIX" || {
ANDROID_BUILD_FAIL+=("Failed to make ANDROID_BUILD_PREFIX directory") ANDROID_BUILD_FAIL+=("Failed to make ANDROID_BUILD_PREFIX directory")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_PREFIX}") ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_PREFIX}")
} }
android_build_check_fail android_build_check_fail
} }
...@@ -147,37 +155,37 @@ function _android_build_opts_process_binaries { ...@@ -147,37 +155,37 @@ function _android_build_opts_process_binaries {
local AR="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar" local AR="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar"
local RANLIB="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ranlib" local RANLIB="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ranlib"
local STRIP="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-strip" local STRIP="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-strip"
if [ ! -x "${CC}" ]; then if [ ! -x "${CC}" ]; then
ANDROID_BUILD_FAIL+=("The CC binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The CC binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${CC}") ANDROID_BUILD_FAIL+=(" ${CC}")
fi fi
if [ ! -x "${CXX}" ]; then if [ ! -x "${CXX}" ]; then
ANDROID_BUILD_FAIL+=("The CXX binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The CXX binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${CXX}") ANDROID_BUILD_FAIL+=(" ${CXX}")
fi fi
if [ ! -x "${LD}" ]; then if [ ! -x "${LD}" ]; then
ANDROID_BUILD_FAIL+=("The LD binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The LD binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${LD}") ANDROID_BUILD_FAIL+=(" ${LD}")
fi fi
if [ ! -x "${AS}" ]; then if [ ! -x "${AS}" ]; then
ANDROID_BUILD_FAIL+=("The AS binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The AS binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${AS}") ANDROID_BUILD_FAIL+=(" ${AS}")
fi fi
if [ ! -x "${AR}" ]; then if [ ! -x "${AR}" ]; then
ANDROID_BUILD_FAIL+=("The AR binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The AR binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${AR}") ANDROID_BUILD_FAIL+=(" ${AR}")
fi fi
if [ ! -x "${RANLIB}" ]; then if [ ! -x "${RANLIB}" ]; then
ANDROID_BUILD_FAIL+=("The RANLIB binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The RANLIB binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${RANLIB}") ANDROID_BUILD_FAIL+=(" ${RANLIB}")
fi fi
if [ ! -x "${STRIP}" ]; then if [ ! -x "${STRIP}" ]; then
ANDROID_BUILD_FAIL+=("The STRIP binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The STRIP binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${STRIP}") ANDROID_BUILD_FAIL+=(" ${STRIP}")
...@@ -191,17 +199,17 @@ function _android_build_opts_process_binaries { ...@@ -191,17 +199,17 @@ function _android_build_opts_process_binaries {
ANDROID_BUILD_OPTS+=("AR=${AR}") ANDROID_BUILD_OPTS+=("AR=${AR}")
ANDROID_BUILD_OPTS+=("RANLIB=${RANLIB}") ANDROID_BUILD_OPTS+=("RANLIB=${RANLIB}")
ANDROID_BUILD_OPTS+=("STRIP=${STRIP}") ANDROID_BUILD_OPTS+=("STRIP=${STRIP}")
android_build_check_fail android_build_check_fail
} }
# Set the ANDROID_BUILD_OPTS variable to a bash array of configure options # Set the ANDROID_BUILD_OPTS variable to a bash array of configure options
function android_build_opts { function android_build_opts {
ANDROID_BUILD_OPTS=() ANDROID_BUILD_OPTS=()
_android_build_opts_process_binaries _android_build_opts_process_binaries
local LIBS="-lc -lgcc -ldl -lc++_shared" local LIBS="-lc -lgcc -ldl -lm -llog -lc++_shared"
local LDFLAGS="-L${ANDROID_BUILD_PREFIX}/lib" local LDFLAGS="-L${ANDROID_BUILD_PREFIX}/lib"
LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_CXXSTL}" LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_CXXSTL}"
CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE" CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE"
...@@ -212,7 +220,7 @@ function android_build_opts { ...@@ -212,7 +220,7 @@ function android_build_opts {
ANDROID_BUILD_OPTS+=("CXXFLAGS=${CXXFLAGS} ${ANDROID_BUILD_EXTRA_CXXFLAGS}") ANDROID_BUILD_OPTS+=("CXXFLAGS=${CXXFLAGS} ${ANDROID_BUILD_EXTRA_CXXFLAGS}")
ANDROID_BUILD_OPTS+=("LDFLAGS=${LDFLAGS} ${ANDROID_BUILD_EXTRA_LDFLAGS}") ANDROID_BUILD_OPTS+=("LDFLAGS=${LDFLAGS} ${ANDROID_BUILD_EXTRA_LDFLAGS}")
ANDROID_BUILD_OPTS+=("LIBS=${LIBS} ${ANDROID_BUILD_EXTRA_LIBS}") ANDROID_BUILD_OPTS+=("LIBS=${LIBS} ${ANDROID_BUILD_EXTRA_LIBS}")
ANDROID_BUILD_OPTS+=("PKG_CONFIG_LIBDIR=${ANDROID_NDK_ROOT}/prebuilt/${HOST_PLATFORM}/lib/pkgconfig") ANDROID_BUILD_OPTS+=("PKG_CONFIG_LIBDIR=${ANDROID_NDK_ROOT}/prebuilt/${HOST_PLATFORM}/lib/pkgconfig")
ANDROID_BUILD_OPTS+=("PKG_CONFIG_PATH=${ANDROID_BUILD_PREFIX}/lib/pkgconfig") ANDROID_BUILD_OPTS+=("PKG_CONFIG_PATH=${ANDROID_BUILD_PREFIX}/lib/pkgconfig")
ANDROID_BUILD_OPTS+=("PKG_CONFIG_SYSROOT_DIR=${ANDROID_BUILD_SYSROOT}") ANDROID_BUILD_OPTS+=("PKG_CONFIG_SYSROOT_DIR=${ANDROID_BUILD_SYSROOT}")
...@@ -220,7 +228,7 @@ function android_build_opts { ...@@ -220,7 +228,7 @@ function android_build_opts {
ANDROID_BUILD_OPTS+=("--with-sysroot=${ANDROID_BUILD_SYSROOT}") ANDROID_BUILD_OPTS+=("--with-sysroot=${ANDROID_BUILD_SYSROOT}")
ANDROID_BUILD_OPTS+=("--host=${TOOLCHAIN_HOST}") ANDROID_BUILD_OPTS+=("--host=${TOOLCHAIN_HOST}")
ANDROID_BUILD_OPTS+=("--prefix=${ANDROID_BUILD_PREFIX}") ANDROID_BUILD_OPTS+=("--prefix=${ANDROID_BUILD_PREFIX}")
android_build_check_fail android_build_check_fail
} }
...@@ -231,14 +239,14 @@ function android_build_opts { ...@@ -231,14 +239,14 @@ function android_build_opts {
function android_build_verify_so { function android_build_verify_so {
local soname="$1" local soname="$1"
shift # Get rid of first argument - the rest represent dependencies shift # Get rid of first argument - the rest represent dependencies
local sofile="${ANDROID_BUILD_PREFIX}/lib/${soname}" local sofile="${ANDROID_BUILD_PREFIX}/lib/${soname}"
if [ ! -f "${sofile}" ]; then if [ ! -f "${sofile}" ]; then
ANDROID_BUILD_FAIL+=("Found no library named ${soname}") ANDROID_BUILD_FAIL+=("Found no library named ${soname}")
ANDROID_BUILD_FAIL+=(" ${sofile}") ANDROID_BUILD_FAIL+=(" ${sofile}")
fi fi
android_build_check_fail android_build_check_fail
if command -v readelf >/dev/null 2>&1 ; then if command -v readelf >/dev/null 2>&1 ; then
local readelf_bin="readelf" local readelf_bin="readelf"
elif command -v greadelf >/dev/null 2>&1 ; then elif command -v greadelf >/dev/null 2>&1 ; then
...@@ -249,7 +257,7 @@ function android_build_verify_so { ...@@ -249,7 +257,7 @@ function android_build_verify_so {
android_build_check_fail android_build_check_fail
local elfoutput=$(LC_ALL=C $readelf_bin -d ${sofile}) local elfoutput=$(LC_ALL=C $readelf_bin -d ${sofile})
local soname_regexp='soname: \[([[:alnum:]\.]+)\]' local soname_regexp='soname: \[([[:alnum:]\.]+)\]'
if [[ $elfoutput =~ $soname_regexp ]]; then if [[ $elfoutput =~ $soname_regexp ]]; then
local parsed_soname="${BASH_REMATCH[1]}" local parsed_soname="${BASH_REMATCH[1]}"
...@@ -261,13 +269,13 @@ function android_build_verify_so { ...@@ -261,13 +269,13 @@ function android_build_verify_so {
ANDROID_BUILD_FAIL+=("Failed to meaningfully parse readelf output for library ${soname}:") ANDROID_BUILD_FAIL+=("Failed to meaningfully parse readelf output for library ${soname}:")
ANDROID_BUILD_FAIL+=(" ${elfoutput}") ANDROID_BUILD_FAIL+=(" ${elfoutput}")
fi fi
for dep_soname do for dep_soname do
if [[ $elfoutput != *"library: [${dep_soname}]"* ]]; then if [[ $elfoutput != *"library: [${dep_soname}]"* ]]; then
ANDROID_BUILD_FAIL+=("Library ${soname} was expected to be linked to library with soname:") ANDROID_BUILD_FAIL+=("Library ${soname} was expected to be linked to library with soname:")
ANDROID_BUILD_FAIL+=(" ${dep_soname}") ANDROID_BUILD_FAIL+=(" ${dep_soname}")
fi fi
done done
android_build_check_fail android_build_check_fail
} }
#!/usr/bin/env bash #!/usr/bin/env bash
function usage {
echo "Usage ./build.sh [ arm | arm64 | x86 | x86_64 ]"
}
# Use directory of current script as the build directory and working directory # Use directory of current script as the build directory and working directory
cd "$( dirname "${BASH_SOURCE[0]}" )" cd "$( dirname "${BASH_SOURCE[0]}" )"
ANDROID_BUILD_DIR="$(pwd)" ANDROID_BUILD_DIR="$(pwd)"
...@@ -10,12 +14,73 @@ source ${ANDROID_BUILD_DIR}/android_build_helper.sh ...@@ -10,12 +14,73 @@ source ${ANDROID_BUILD_DIR}/android_build_helper.sh
# Choose a C++ standard library implementation from the ndk # Choose a C++ standard library implementation from the ndk
ANDROID_BUILD_CXXSTL="gnustl_shared_49" ANDROID_BUILD_CXXSTL="gnustl_shared_49"
BUILD_ARCH=$1
if [ -z $BUILD_ARCH ]; then
usage
exit 1
fi
case $(uname | tr '[:upper:]' '[:lower:]') in
linux*)
export HOST_PLATFORM=linux-x86_64
;;
darwin*)
export HOST_PLATFORM=darwin-x86_64
;;
*)
echo "Unsupported platform"
exit 1
;;
esac
# Set default values used in ci builds
export NDK_VERSION=${NDK_VERSION:-android-ndk-r20}
# With NDK r20, the minimum SDK version range is [16, 29].
# SDK version 21 is the minimum version for 64-bit builds.
export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
# Set variables for each architecture
HOST_ARM="arm-linux-androideabi"
HOST_ARM64="aarch64-linux-android"
HOST_X86="i686-linux-android"
HOST_X86_64="x86_64-linux-android"
COMP_ARM="armv7a-linux-androideabi${MIN_SDK_VERSION}"
COMP_ARM64="aarch64-linux-android${MIN_SDK_VERSION}"
COMP_X86="i686-linux-android${MIN_SDK_VERSION}"
COMP_X86_64="x86_64-linux-android${MIN_SDK_VERSION}"
CXXSTL_ARM="armeabi-v7a"
CXXSTL_ARM64="arm64-v8a"
CXXSTL_X86="x86"
CXXSTL_X86_64="x86_64"
ARCH_ARM="arm"
ARCH_ARM64="arm64"
ARCH_X86="x86"
ARCH_X86_64="x86_64"
if [ $BUILD_ARCH == "arm" ]; then
android_build_arch $HOST_ARM $COMP_ARM $CXXSTL_ARM $ARCH_ARM
elif [ $BUILD_ARCH == "x86" ]; then
android_build_arch $HOST_X86 $COMP_X86 $CXXSTL_X86 $ARCH_X86
elif [ $BUILD_ARCH == "arm64" ]; then
android_build_arch $HOST_ARM64 $COMP_ARM64 $CXXSTL_ARM64 $ARCH_ARM64
elif [ $BUILD_ARCH == "x86_64" ]; then
android_build_arch $HOST_X86_64 $COMP_X86_64 $CXXSTL_X86_64 $ARCH_X86_64
else
usage
exit 1
fi
# Set up android build environment and set ANDROID_BUILD_OPTS array # Set up android build environment and set ANDROID_BUILD_OPTS array
android_build_env android_build_env
android_build_opts android_build_opts
# Use a temporary build directory # Use a temporary build directory
cache="/tmp/android_build/${TOOLCHAIN_NAME}" cache="/tmp/android_build/${TOOLCHAIN_ARCH}"
rm -rf "${cache}" rm -rf "${cache}"
mkdir -p "${cache}" mkdir -p "${cache}"
...@@ -56,7 +121,7 @@ LIBTOOL_EXTRA_LDFLAGS='-avoid-version' ...@@ -56,7 +121,7 @@ LIBTOOL_EXTRA_LDFLAGS='-avoid-version'
(android_build_verify_so ${VERIFY} &> /dev/null) || { (android_build_verify_so ${VERIFY} &> /dev/null) || {
rm -rf "${cache}/libzmq" rm -rf "${cache}/libzmq"
(cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && make clean) (cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && make clean)
(cd "${cache}/libzmq" && ./autogen.sh \ (cd "${cache}/libzmq" && ./autogen.sh \
&& ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" ${CURVE} --without-docs \ && ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" ${CURVE} --without-docs \
&& make -j 4 \ && make -j 4 \
......
#!/usr/bin/env bash #!/usr/bin/env bash
NDK_VERSION=android-ndk-r20 export NDK_VERSION=android-ndk-r20
NDK_ABI_VERSION=4.9 export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}"
if [ $TRAVIS_OS_NAME == "linux" ] case $(uname | tr '[:upper:]' '[:lower:]') in
then linux*)
HOST_PLATFORM=linux-x86_64 HOST_PLATFORM=linux-x86_64
elif [ $TRAVIS_OS_NAME == "osx" ] ;;
then darwin*)
HOST_PLATFORM=darwin-x86_64 HOST_PLATFORM=darwin-x86_64
else ;;
echo "Unsupported platform $TRAVIS_OS_NAME" *)
echo "Unsupported platform"
exit 1 exit 1
fi ;;
esac
if [ ! -d "/tmp/${NDK_VERSION}" ] ; then if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
export FILENAME=$NDK_VERSION-$HOST_PLATFORM.zip export FILENAME=$NDK_VERSION-$HOST_PLATFORM.zip
(cd '/tmp' \ (cd '/tmp' \
&& wget http://dl.google.com/android/repository/$FILENAME -O $FILENAME \ && wget http://dl.google.com/android/repository/$FILENAME -O $FILENAME &> /dev/null \
&& unzip -q $FILENAME) || exit 1 && unzip -q $FILENAME) || exit 1
unset FILENAME unset FILENAME
fi fi
function _build_arch { ./build.sh "arm"
export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}" ./build.sh "arm64"
export TOOLCHAIN_PATH="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin" ./build.sh "x86"
export TOOLCHAIN_HOST=$1 ./build.sh "x86_64"
export TOOLCHAIN_COMP=$2
export TOOLCHAIN_CXXSTL=$3
export TOOLCHAIN_ARCH=$4
export TOOLCHAIN_NAME="${TOOLCHAIN_HOST}-${NDK_ABI_VERSION}"
source ./build.sh
}
# Define the minimum Android API level for the library to run.
# With NDK r20, the minimum SDK version range is [16, 29]
export MIN_SDK_VERSION="21"
HOST_ARM="arm-linux-androideabi"
HOST_ARM64="aarch64-linux-android"
HOST_X86="i686-linux-android"
HOST_X86_64="x86_64-linux-android"
COMP_ARM="armv7a-linux-androideabi${MIN_SDK_VERSION}"
COMP_ARM64="aarch64-linux-android${MIN_SDK_VERSION}"
COMP_X86="i686-linux-android${MIN_SDK_VERSION}"
COMP_X86_64="x86_64-linux-android${MIN_SDK_VERSION}"
CXXSTL_ARM="armeabi-v7a"
CXXSTL_ARM64="arm64-v8a"
CXXSTL_X86="x86"
CXXSTL_X86_64="x86_64"
ARCH_ARM="arm"
ARCH_ARM64="arm64"
ARCH_X86="x86"
ARCH_X86_64="x86_64"
_build_arch $HOST_ARM $COMP_ARM $CXXSTL_ARM $ARCH_ARM
_build_arch $HOST_X86 $COMP_X86 $CXXSTL_X86 $ARCH_X86
if [[ $MIN_SDK_VERSION -ge 21 ]] ; then
_build_arch $HOST_ARM64 $COMP_ARM64 $CXXSTL_ARM64 $ARCH_ARM64
_build_arch $HOST_X86_64 $COMP_X86_64 $CXXSTL_X86_64 $ARCH_X86_64
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment