Files
mtgodot-poc/build-android-native.sh
T
shenleiandClaude Opus 5.5 53d06c3c26 android-native: real-server login by default, readable CJK text, 16 KB pages
- FreeType: add the cff/psaux/pshinter modules (from the pinned 2.13.3
  tarball, same sha256). Android's only CJK font is the CFF2
  NotoSansCJK-Regular.ttc, which the TrueType-only build could not open,
  so every Chinese glyph drew as a box.
- Font oversample rounds the UI density up: Android's 1760x800 UI on a
  2376x1080 screen is 1.35, which rounded to 1x bilevel glyphs stretched
  1.35x. Now 2x anti-aliased glyphs are scaled down. macOS 2.0 unchanged.
- MainActivity: a launcher start (no intent args) opens the login screen
  against 192.168.21.203 instead of auto-logging into the in-process fake
  server; explicit args still select the fake-server smoke flow.
- build-android-native.sh: ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON for SDL3
  and libmain (LOAD alignment 0x1000 -> 0x4000), with a stamp that
  rebuilds a cached pre-flag SDL3. Clears Android's 16 KB compat warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 12:16:38 +09:00

90 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the native (SDL3 + Vulkan) 40250 client as an Android arm64 APK.
# ./build-android-native.sh [Debug|Release] [--install]
# Output: android-native/app/build/outputs/apk/debug/app-debug.apk
# The 1.4 GB Client/ directory is not in the APK; push it once with ./push-android-client.sh.
set -euo pipefail
cd "$(dirname "$0")"
REPO="$PWD"
CONFIG=Release
INSTALL=0
for a in "$@"; do
case "$a" in
Debug|Release) CONFIG="$a" ;;
--install) INSTALL=1 ;;
*) echo "usage: $0 [Debug|Release] [--install]" >&2; exit 2 ;;
esac
done
API=24
OUT="$REPO/build-android-native"
JOBS="${JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)}"
SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}"
# --- NDK: $ANDROID_NDK_HOME, else the installed 27.x, else the newest ---
NDK="${ANDROID_NDK_ROOT:-${ANDROID_NDK_HOME:-}}"
if [ -z "$NDK" ] && [ -d "$SDK/ndk" ]; then
v=$(ls -1 "$SDK/ndk" | grep '^27\.' | sort -V | tail -1 || true)
[ -n "$v" ] || v=$(ls -1 "$SDK/ndk" | sort -V | tail -1)
NDK="$SDK/ndk/$v"
fi
[ -f "$NDK/build/cmake/android.toolchain.cmake" ] || { echo "Android NDK not found (set ANDROID_NDK_HOME)" >&2; exit 1; }
echo "NDK: $NDK"
TOOLCHAIN="$NDK/build/cmake/android.toolchain.cmake"
GLSLC="${GLSLC:-$(command -v glslc || true)}"
[ -n "$GLSLC" ] || { echo "glslc not found (brew install shaderc)" >&2; exit 1; }
# --- SDL3 source (Java SDLActivity + libSDL3.so), same release as the macOS build ---
SDL_VER=3.4.16
SDL_SHA256=7322236cd12090c3eb40b9728be4d49c76f66ad17d04369584d4ecad5cf77c68
SDL_SRC="$OUT/_deps/SDL3-$SDL_VER"
if [ ! -f "$SDL_SRC/CMakeLists.txt" ]; then
mkdir -p "$OUT/_deps"
tarball="$OUT/_deps/SDL3-$SDL_VER.tar.gz"
curl -fL -o "$tarball" "https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VER/SDL3-$SDL_VER.tar.gz"
echo "$SDL_SHA256 $tarball" | shasum -a 256 -c -
tar xzf "$tarball" -C "$OUT/_deps"
fi
# 16 KB page alignment (Android 15+ devices check it): NDK r27 links with max-page-size=16384 when
# ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES is on. The stamp rebuilds an SDL3 cached from before the flag.
PAGE_SIZES=-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON
if [ ! -f "$OUT/sdl3/lib/libSDL3.so" ] || [ ! -f "$OUT/sdl3/.page16k" ]; then
rm -rf "$OUT/sdl3-build" "$OUT/sdl3"
cmake -S "$SDL_SRC" -B "$OUT/sdl3-build" -G "Unix Makefiles" \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM="android-$API" "$PAGE_SIZES" \
-DCMAKE_BUILD_TYPE=Release -DSDL_SHARED=ON -DSDL_STATIC=OFF -DSDL_TEST_LIBRARY=OFF \
-DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX="$OUT/sdl3"
cmake --build "$OUT/sdl3-build" -j "$JOBS"
cmake --install "$OUT/sdl3-build"
touch "$OUT/sdl3/.page16k"
fi
# --- libmain.so (native_render + port_platform + embedded Python) and its assets ---
cmake -S . -B "$OUT/app-build" -G "Unix Makefiles" -Wno-deprecated \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM="android-$API" "$PAGE_SIZES" \
-DCMAKE_BUILD_TYPE="$CONFIG" -DMT_BUILD_TOOLS=OFF -DBUILD_TESTING=OFF \
-DMT_BUILD_NATIVE_RENDER=ON -DSDL3_DIR="$OUT/sdl3/lib/cmake/SDL3" \
-DCMAKE_FIND_ROOT_PATH="$OUT/sdl3" -DGLSLC="$GLSLC" >/dev/null
cmake --build "$OUT/app-build" --target main mt_native_android_assets -j "$JOBS"
mkdir -p "$OUT/jniLibs/arm64-v8a"
cp -f "$OUT/sdl3/lib/libSDL3.so" "$OUT/app-build/native_render/libmain.so" "$OUT/jniLibs/arm64-v8a/"
STRIP=$(ls -1d "$NDK"/toolchains/llvm/prebuilt/*/bin/llvm-strip | head -1)
"$STRIP" --strip-unneeded "$OUT/jniLibs/arm64-v8a/libSDL3.so" "$OUT/jniLibs/arm64-v8a/libmain.so"
# --- APK ---
if [ -z "${JAVA_HOME:-}" ]; then
for j in /opt/homebrew/opt/openjdk@21 /opt/homebrew/opt/openjdk@17; do
[ -x "$j/bin/java" ] && { export JAVA_HOME="$j"; break; }
done
fi
export ANDROID_HOME="$SDK"
variant=Debug # debug-signed either way (sideload); CONFIG picks the native optimisation level
(cd android-native && ./gradlew --quiet "assemble$variant")
APK="$REPO/android-native/app/build/outputs/apk/debug/app-debug.apk"
ls -la "$APK"
if [ "$INSTALL" = 1 ]; then
adb install -r "$APK"
fi