android: build.sh installs and syncs the game files when a phone is attached

After building the APK, android/build.sh now picks the attached device (ANDROID_SERIAL for several),
installs the APK (reinstalling on a signature mismatch), syncs the zh client into files/Client and, with
--launch, wakes the phone and starts the app. Without a device it only builds.

push-client.sh is now incremental (android/sync_client.py): the device keeps files/Client/.mt_sync
(size, mtime, path of what the last sync wrote), so later syncs send only new and changed files as one
tar streamed through `adb shell -T run-as` (no copy in /data/local/tmp) and delete the ones gone
locally. Only game resources are synced; settings and logs the app writes there are kept. --locale zh
rebuilds build/zh-locale/Client first when its inputs changed. android/adb_env.sh picks adb and falls
back to server port 5038 when :5037 cannot bind.

Verified against a fake adb device: first sync (1.4 GB, byte-identical), no-op resync, changed files,
deletions, locale switch, --full, the install/launch path and the no-device path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 16:36:21 +09:00
co-authored by Claude Opus 5.5
parent f9cd63713f
commit cd9e5b259d
10 changed files with 363 additions and 64 deletions
+10 -35
View File
@@ -1,39 +1,14 @@
#!/usr/bin/env bash
# Copy the 40250 Client/ directory into the Android app's private files/ (SDL_GetPrefPath), where
# src/host looks for files/Client/pack/Index. Needs the debug APK installed (run-as).
# ./android/push-client.sh [--locale XX] [CLIENT_DIR]
# --locale XX writes the pushed locale.cfg from CLIENT_DIR/locale_XX.cfg. --locale zh defaults
# CLIENT_DIR to build/zh-locale/Client (scripts/build_zh_locale.py), whose pack/ registers locale_zh.
# Sync the 40250 game files into the Android app's private files/ (SDL_GetPrefPath), where src/host looks
# for files/Client/pack/Index. Only files changed since the last sync are sent (android/sync_client.py).
# Needs the debug APK installed (run-as).
# ./android/push-client.sh [--locale XX] [--full] [--dry-run] [CLIENT_DIR]
# --locale XX writes the pushed locale.cfg from CLIENT_DIR/locale_XX.cfg. --locale zh defaults CLIENT_DIR
# to build/zh-locale/Client (scripts/build_zh_locale.py, rebuilt first when its inputs changed).
# --full deletes the synced resources on the device and pushes everything again.
# Symbolic links in CLIENT_DIR (the zh client links the original packs) are copied as their targets.
set -euo pipefail
cd "$(dirname "$0")/.."
PKG=org.metin2port.client
LOCALE=""
if [ "${1:-}" = "--locale" ]; then
LOCALE="${2:?--locale needs a locale code}"
shift 2
fi
if [ "$LOCALE" = zh ]; then
CLIENT="${1:-build/zh-locale/Client}"
else
CLIENT="${1:-Client}"
fi
[ -f "$CLIENT/pack/Index" ] || { echo "$CLIENT/pack/Index not found" >&2; exit 1; }
# The archive's top directory is basename(CLIENT DIR); the app reads files/Client.
[ "$(basename "$CLIENT")" = Client ] || { echo "CLIENT_DIR must be named Client" >&2; exit 1; }
if [ -n "$LOCALE" ]; then
[ -f "$CLIENT/locale_$LOCALE.cfg" ] || { echo "$CLIENT/locale_$LOCALE.cfg not found" >&2; exit 1; }
pack="$(cut -d' ' -f3 < "$CLIENT/locale_$LOCALE.cfg" | tr -d '\r\n')"
tr -d '\r' < "$CLIENT/pack/Index" | grep -qxF "locale_$pack" ||
{ echo "locale_$pack is not registered in $CLIENT/pack/Index" >&2; exit 1; }
fi
TMP=/data/local/tmp/mt-client.tar
echo "packing $CLIENT ..."
tar -h -C "$(dirname "$CLIENT")" -cf - "$(basename "$CLIENT")" | adb shell "cat > $TMP"
echo "unpacking into $PKG files/ ..."
adb shell "run-as $PKG sh -c 'mkdir -p files && rm -rf files/Client && cd files && tar -xf $TMP' && rm -f $TMP"
if [ -n "$LOCALE" ]; then
adb shell "run-as $PKG sh -c 'cp files/Client/locale_$LOCALE.cfg files/Client/locale.cfg'"
echo "locale.cfg: $(adb shell "run-as $PKG cat files/Client/locale.cfg")"
fi
adb shell "run-as $PKG ls files/Client/pack/Index" >/dev/null && echo "done: files/Client"
. android/adb_env.sh
adb_device
exec python3 android/sync_client.py "$@"