Merge pull request #3828 from sappo/master

Android build helper improvement + fix for prefix dir
This commit is contained in:
Luca Boccassi 2020-02-12 22:05:11 +00:00 committed by GitHub
commit 98e82ddff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 55 deletions

View File

@ -22,6 +22,10 @@ To specify the minimum sdk version set the environment variable below:
export MIN_SDK_VERSION=21 # Default value if unset
To specify the prefix directory set the environment variable below:
export ANDROID_BUILD_DIR=./builds/android/prefix/<android_arch> # Default value if unset
## Build
In the android directory, run:

View File

@ -2,21 +2,21 @@
#
# Copyright (c) 2014, Joe Eli McIlvain
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -69,12 +69,36 @@ function android_build_check_fail {
fi
}
function android_build_arch {
function android_build_set_env {
BUILD_ARCH=$1
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
# Set variables for each architecture
if [ $BUILD_ARCH == "arm" ]; then
export TOOLCHAIN_HOST="arm-linux-androideabi"
export TOOLCHAIN_COMP="armv7a-linux-androideabi${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="armeabi-v7a"
export TOOLCHAIN_ARCH="arm"
elif [ $BUILD_ARCH == "x86" ]; then
export TOOLCHAIN_HOST="i686-linux-android"
export TOOLCHAIN_COMP="i686-linux-android${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="x86"
export TOOLCHAIN_ARCH="x86"
elif [ $BUILD_ARCH == "arm64" ]; then
export TOOLCHAIN_HOST="aarch64-linux-android"
export TOOLCHAIN_COMP="aarch64-linux-android${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="arm64-v8a"
export TOOLCHAIN_ARCH="arm64"
elif [ $BUILD_ARCH == "x86_64" ]; then
export TOOLCHAIN_HOST="x86_64-linux-android"
export TOOLCHAIN_COMP="x86_64-linux-android${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="x86_64"
export TOOLCHAIN_ARCH="x86_64"
fi
export ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}"
export ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}"
}
function android_build_env {
@ -101,9 +125,9 @@ function android_build_env {
ANDROID_BUILD_FAIL+=(" (eg. \"armv7a-linux-androideabi\")")
fi
if [ -z "$TOOLCHAIN_CXXSTL" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_CXXSTL environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7abi\")")
if [ -z "$TOOLCHAIN_ABI" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_ABI environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7a\")")
fi
if [ -z "$TOOLCHAIN_ARCH" ]; then
@ -129,15 +153,11 @@ function android_build_env {
##
# Set up some local variables and check them
ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}"
if [ ! -d "$ANDROID_BUILD_SYSROOT" ]; then
ANDROID_BUILD_FAIL+=("The ANDROID_BUILD_SYSROOT directory does not exist")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_SYSROOT}")
fi
ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}"
mkdir -p "$ANDROID_BUILD_PREFIX" || {
ANDROID_BUILD_FAIL+=("Failed to make ANDROID_BUILD_PREFIX directory")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_PREFIX}")
@ -211,7 +231,7 @@ function android_build_opts {
local LIBS="-lc -lgcc -ldl -lm -llog -lc++_shared"
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_ABI}"
CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE"
CPPFLAGS+=" -I${ANDROID_BUILD_PREFIX}/include"

View File

@ -6,16 +6,15 @@ function usage {
# Use directory of current script as the build directory and working directory
cd "$( dirname "${BASH_SOURCE[0]}" )"
ANDROID_BUILD_DIR="$(pwd)"
ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-`pwd`}"
# Get access to android_build functions and variables
source ${ANDROID_BUILD_DIR}/android_build_helper.sh
source ./android_build_helper.sh
# Choose a C++ standard library implementation from the ndk
ANDROID_BUILD_CXXSTL="gnustl_shared_49"
BUILD_ARCH=$1
if [ -z $BUILD_ARCH ]; then
usage
exit 1
@ -41,41 +40,8 @@ export NDK_VERSION=${NDK_VERSION:-android-ndk-r20}
# 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
android_build_set_env $BUILD_ARCH
android_build_env
android_build_opts