Files
mtgodot-poc/export-android.sh

80 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the Android APK end to end: native GDExtension .so -> Godot export -> (opt) install.
#
# ./export-android.sh [Debug|Release] [--install]
#
# Prereqs (one-time), see docs/PLATFORMS.md:
# - Android SDK at ~/Library/Android/sdk with an NDK under ndk/<ver>
# (sdkmanager "ndk;27.2.12479018" "platforms;android-35" "build-tools;35.0.0")
# - JDK 17+ (brew install openjdk@21)
# - Godot 4.7.1 export templates installed
# - ./gen-debug-keystore.sh (once)
# - editor_settings-4.7.tres: export/android/{android_sdk_path,java_sdk_path,debug_keystore}
set -euo pipefail
cd "$(dirname "$0")"
CONFIG="${1:-Debug}"
INSTALL=0
[ "${2:-}" = "--install" ] && INSTALL=1
SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}"
export ANDROID_NDK_ROOT="${ANDROID_NDK_ROOT:-$SDK/ndk/$(ls -1 "$SDK/ndk" 2>/dev/null | sort -V | tail -1)}"
export JAVA_HOME="${JAVA_HOME:-/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home}"
[ -d "$JAVA_HOME" ] || export JAVA_HOME=/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home
GODOT="${GODOT:-godot}"
ADB="${ADB:-$SDK/platform-tools/adb}"
case "$CONFIG" in
Release)
MODE="--export-release"
OUT="build/export/mtgodot-poc-release.apk"
;;
*)
MODE="--export-debug"
OUT="build/export/mtgodot-poc.apk"
;;
esac
echo ">> NDK: $ANDROID_NDK_ROOT"
echo ">> JDK: $JAVA_HOME"
# 1. native GDExtension
./build-android.sh "$CONFIG"
# 2. bake the AssetResolver index (PCK can't std::filesystem-scan on device).
# Regenerate whenever assets/ changes. Harmless if assets are missing.
"$GODOT" --headless --path project --script bake_asset_index.gd || \
echo ">> (asset_index bake skipped — no assets on this machine)"
# 3. Godot export
mkdir -p build/export
"$GODOT" --headless --path project "$MODE" "Android" "$(pwd)/$OUT"
echo
echo ">> APK: $OUT (index: $([ -f assets/asset_index.txt ] && echo baked || echo MISSING))"
unzip -l "$OUT" | grep -E "lib/arm64-v8a/.*\.so" || true
# 3. optional install (+ push the asset zip if it exists)
if [ "$INSTALL" = 1 ]; then
"$ADB" devices -l
"$ADB" install -r "$OUT"
if [ -f build/export/assets.zip ]; then
DEST="/sdcard/Android/data/org.internal.mtgodotpoc/files/assets.zip"
echo ">> pushing assets.zip ($(du -h build/export/assets.zip | cut -f1)) -> $DEST"
"$ADB" shell mkdir -p /sdcard/Android/data/org.internal.mtgodotpoc/files/ || true
"$ADB" push build/export/assets.zip "$DEST"
if [ "$CONFIG" != "Release" ]; then
echo ">> copying assets.zip into the Debug app user:// directory"
# Android 14/15 may deny run-as reading /sdcard even for the app's own
# external files directory. Stream through adb instead.
"$ADB" shell "run-as org.internal.mtgodotpoc sh -c 'cat > files/assets.zip'" \
< build/export/assets.zip
fi
else
echo ">> NOTE: no build/export/assets.zip — run ./pack-assets.sh; the world won't render without it"
fi
"$ADB" shell am start -W -n org.internal.mtgodotpoc/com.godot.game.GodotAppLauncher \
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo ">> logcat: $ADB logcat -s godot GodotError Godot"
fi