2021-08-19 20:38:05 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -e -x -u
|
|
|
|
|
2023-01-14 01:06:00 +03:00
|
|
|
# Get directory this script is in
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2022-11-08 21:19:12 +03:00
|
|
|
|
2021-08-19 20:38:05 +03:00
|
|
|
OSNAME=android
|
2023-01-14 01:06:00 +03:00
|
|
|
BUILD_CONFIG=Release
|
|
|
|
abi_name=x86_64
|
2022-11-08 21:19:12 +03:00
|
|
|
target_dir=''
|
|
|
|
if [[ -n ${_BUILD_CFG-} ]]; then
|
|
|
|
IFS=' ' read -r abi_name target_dir <<< ${_BUILD_CFG}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${target_dir}" ]]; then
|
2023-01-14 01:06:00 +03:00
|
|
|
target_dir="${SCRIPT_DIR}/out/$OSNAME/${BUILD_CONFIG}"
|
2022-11-08 21:19:12 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z ${NDK_ROOT+x} ]]; then
|
|
|
|
if [[ $OSTYPE == 'darwin'* ]]; then
|
|
|
|
NDK_ROOT=`ls -Ad $HOME/Library/Android/sdk/ndk/* 2>/dev/null | tail -1`
|
|
|
|
else
|
|
|
|
NDK_ROOT=`ls -Ad $HOME/Android/Sdk/ndk/* 2>/dev/null | tail -1`
|
|
|
|
fi
|
|
|
|
fi
|
2022-10-12 00:53:22 +03:00
|
|
|
if [[ -z "${NDK_ROOT}" ]]; then
|
2021-08-19 20:38:05 +03:00
|
|
|
echo "ERROR: cannot find where NDK was installed, using NDK_ROOT to specify it"
|
|
|
|
exit 7
|
|
|
|
fi
|
2022-10-05 02:22:28 +03:00
|
|
|
if [[ -z ${ANDROID_SDK_ROOT+x} ]]; then
|
2023-01-14 01:06:00 +03:00
|
|
|
export ANDROID_SDK_ROOT="$(dirname $(dirname "${NDK_ROOT}"))"
|
2022-10-05 02:22:28 +03:00
|
|
|
fi
|
2022-10-12 00:53:22 +03:00
|
|
|
if [[ -z ${ANDROID_NDK_VERSION+x} ]]; then
|
2023-01-14 01:06:00 +03:00
|
|
|
CURRENT_NDK_VERSION=$(basename "${NDK_ROOT}")
|
2022-10-12 00:53:22 +03:00
|
|
|
else
|
|
|
|
CURRENT_NDK_VERSION=${ANDROID_NDK_VERSION}
|
|
|
|
fi
|
2021-08-19 20:38:05 +03:00
|
|
|
|
2023-01-14 01:06:00 +03:00
|
|
|
# the minimum API level is 24, i.e., due to the great change of file system permission in Android 7
|
|
|
|
ANDROID_API_LEVEL=24
|
|
|
|
|
2023-08-12 10:45:59 +03:00
|
|
|
# build openssl and curl for azure ops
|
|
|
|
export ANDROID_API_LEVEL=${ANDROID_API_LEVEL}
|
|
|
|
export ANDROID_NDK_ROOT=${NDK_ROOT}
|
2024-07-30 00:21:17 +03:00
|
|
|
# pushd "${SCRIPT_DIR}/prebuild"
|
|
|
|
# ./build_curl_for_android.sh ${abi_name}
|
|
|
|
# popd
|
2023-08-12 10:45:59 +03:00
|
|
|
|
2023-01-14 01:06:00 +03:00
|
|
|
mkdir -p "${target_dir}"
|
|
|
|
pushd "${target_dir}"
|
2022-11-08 21:19:12 +03:00
|
|
|
cmake "$@" \
|
2023-01-14 01:06:00 +03:00
|
|
|
-DCMAKE_TOOLCHAIN_FILE="${NDK_ROOT}/build/cmake/android.toolchain.cmake" \
|
|
|
|
-DANDROID_ABI=${abi_name} \
|
|
|
|
-DANDROID_PLATFORM=android-${ANDROID_API_LEVEL} \
|
|
|
|
-DANDROID_NDK_VERSION=${CURRENT_NDK_VERSION} \
|
|
|
|
-DOCOS_BUILD_ANDROID=ON \
|
|
|
|
"${SCRIPT_DIR}" && cmake --build . --config ${BUILD_CONFIG} --parallel
|
|
|
|
popd
|
|
|
|
|
|
|
|
JAVA_ROOT="${SCRIPT_DIR}/java"
|
|
|
|
pushd "${JAVA_ROOT}"
|
|
|
|
"${JAVA_ROOT}/gradlew" \
|
|
|
|
clean build publish \
|
|
|
|
--no-daemon \
|
|
|
|
-b "${JAVA_ROOT}/build-android.gradle" \
|
|
|
|
-c "${JAVA_ROOT}/settings-android.gradle" \
|
|
|
|
-DjniLibsDir="${target_dir}/java/android" \
|
|
|
|
-DbuildDir="${target_dir}/java/build/android" \
|
|
|
|
-DpublishDir="${target_dir}/aar_out" \
|
|
|
|
-DminSdkVer=${ANDROID_API_LEVEL} \
|
|
|
|
-DndkVer=${CURRENT_NDK_VERSION}
|
2022-11-08 21:19:12 +03:00
|
|
|
popd
|