Skip to content

Instantly share code, notes, and snippets.

@jeffdgr8
Last active August 22, 2024 23:26
Show Gist options
  • Save jeffdgr8/22037c8b98fc7c597a822e735bfe3c33 to your computer and use it in GitHub Desktop.
Save jeffdgr8/22037c8b98fc7c597a822e735bfe3c33 to your computer and use it in GitHub Desktop.
Build Couchbase Lite Core binaries for Couchbase Lite Android SDK
#!/bin/sh
# Run from Couchbase Lite Java repo root to generate
# the Android libLiteCore.so binaries in common/lite-core
# https://github.com/couchbase/couchbase-lite-java-ce-root
# Couchbase Lite Core repo location
CORE_REPO_PATH="../couchbase-lite-core"
# Community or Enterprise
BUILD_ENTERPRISE=OFF # or ON
# Build type
# 1. Release: high optimization level, no debug info, code or asserts.
# 2. Debug: No optimization, asserts enabled, [custom debug (output) code enabled],
# debug info included in executable (so you can step through the code with a
# debugger and have address to source-file:line-number translation).
# 3. RelWithDebInfo: optimized, *with* debug info, but no debug (output) code or asserts.
# 4. MinSizeRel: same as Release but optimizing for size rather than speed.
CMAKE_BUILD_TYPE=Release
# Architectures (arm64-v8a armeabi-v7a x86_64 x86)
ARCHS="arm64-v8a armeabi-v7a x86_64 x86"
# Android SDK & NDK
MIN_ANDROID_API=22
NDK_VER="25.2.9519653"
NDK_PATH="$ANDROID_HOME/ndk/$NDK_VER"
if ! command -v cmake &> /dev/null
then
echo "cmake could not be found (install https://cmake.org or set PATH)"
exit 1
fi
if ! command -v ninja &> /dev/null
then
echo "ninja could not be found (install https://ninja-build.org or set PATH)"
exit 2
fi
if [ -z $ANDROID_HOME ]; then
echo "ANDROID_HOME must be defined (path to Android SDK)"
exit 3
fi
if [ ! -d $NDK_PATH ]; then
echo "NDK $NDK_VER is not installed (install or update NDK_VER in script)"
exit 4
fi
# https://github.com/couchbase/couchbase-lite-core/tree/master#android
REPO_ROOT=$PWD
BUILD_ROOT="build_cmake/android"
LIB_ROOT="$REPO_ROOT/common/lite-core"
# Build binary
build_arch() {
mkdir -p $BUILD_PATH
cd $BUILD_PATH
cmake \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE="$NDK_PATH/build/cmake/android.toolchain.cmake" \
-DCMAKE_MAKE_PROGRAM=ninja \
-DANDROID_NATIVE_API_LEVEL=$MIN_ANDROID_API \
-DANDROID_ABI=$ARCH \
-DBUILD_ENTERPRISE=$BUILD_ENTERPRISE \
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
../../../..
cmake --build . --target LiteCore
cd ../../../..
}
# Copy binary and headers to Java SDK location
copy_arch() {
LIB_PATH="$LIB_ROOT/android/$ARCH"
BIN_PATH="$LIB_PATH/lib"
mkdir -p $BIN_PATH
cp "$BUILD_PATH/libLiteCore.so" $BIN_PATH
HEADER_PATH="$LIB_PATH/include"
mkdir -p $HEADER_PATH
cp -R "C/include/" $HEADER_PATH
cp -R "vendor/fleece/API/" $HEADER_PATH
}
cd $CORE_REPO_PATH
# Remove previous builds
if [ -d $BUILD_ROOT ]; then
rm -r $BUILD_ROOT
fi
if [ -d "$LIB_ROOT/android" ]; then
rm -r "$LIB_ROOT/android"
fi
for ARCH in $ARCHS; do
BUILD_PATH="$BUILD_ROOT/lib/$ARCH"
build_arch
copy_arch
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment