android-native: SDL3 APK build for the native client
build-android-native.sh downloads SDL 3.4.16 (sha256-checked), builds libSDL3.so and libmain.so (native_render + port_platform + embedded Python) at API 24, and wraps them in the SDLActivity shell under android-native/ (package org.metin2port.client). push-android-client.sh copies the 40250 Client directory into the app's files/ with run-as (--locale XX selects locale_XX.cfg). port_logic links with --no-dependent-libraries on ELF targets so the verbatim `#pragma comment(lib, ...)` lines do not break lld. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0b701d88c3
commit
fd051cc3ed
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#!/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
|
||||
if [ ! -f "$OUT/sdl3/lib/libSDL3.so" ]; then
|
||||
cmake -S "$SDL_SRC" -B "$OUT/sdl3-build" -G "Unix Makefiles" \
|
||||
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM="android-$API" \
|
||||
-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"
|
||||
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" \
|
||||
-DCMAKE_BUILD_TYPE="$CONFIG" -DMTGODOT_BUILD_TOOLS=OFF -DBUILD_TESTING=OFF \
|
||||
-DMT_BUILD_NATIVE_RENDER_PROTOTYPE=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
|
||||
Reference in New Issue
Block a user