Files
mtgodot-poc/build-android.sh

51 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Cross-compile the mtgodot GDExtension for Android (OnePlus 13 / arm64 / Vulkan).
# Produces project/bin/libmtgodot.android.template_{debug,release}.arm64.so.
#
# On-device run + APK export is the rest of BACKLOG F2; see docs/PLATFORMS.md.
#
# Needs the Android NDK. Point at it with ANDROID_NDK_ROOT (or install via
# Android Studio → SDK Manager → NDK, default ~/Library/Android/sdk/ndk/<ver>).
set -euo pipefail
cd "$(dirname "$0")"
CONFIG="${1:-Debug}" # Debug | Release
ABI="${ANDROID_ABI:-arm64-v8a}"
API="${ANDROID_PLATFORM:-24}"
BUILD_DIR="build-android"
JOBS="${JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)}"
# --- locate the NDK ---
NDK="${ANDROID_NDK_ROOT:-${ANDROID_NDK_HOME:-}}"
if [ -z "$NDK" ]; then
SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}"
if [ -d "$SDK/ndk" ]; then
NDK="$SDK/ndk/$(ls -1 "$SDK/ndk" | sort -V | tail -1)"
fi
fi
if [ -z "$NDK" ] || [ ! -f "$NDK/build/cmake/android.toolchain.cmake" ]; then
echo "Android NDK not found. Set ANDROID_NDK_ROOT to an NDK with" >&2
echo " build/cmake/android.toolchain.cmake (install via Android Studio SDK Manager)." >&2
exit 1
fi
echo "NDK: $NDK"
if [ ! -f extension/godot-cpp/cmake/android.cmake ]; then
echo "godot-cpp submodule missing — git submodule update --init --recursive" >&2
exit 1
fi
cmake -S . -B "$BUILD_DIR" -G "Unix Makefiles" \
-DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI="$ABI" \
-DANDROID_PLATFORM="android-$API" \
-DCMAKE_BUILD_TYPE="$CONFIG" \
-DMTGODOT_BUILD_TOOLS=OFF \
-DBUILD_TESTING=OFF
cmake --build "$BUILD_DIR" --target mtgodot -j "$JOBS"
echo
echo "Android ($CONFIG / $ABI) library:"
ls -la project/bin/libmtgodot.android.*.so