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>
42 lines
2.0 KiB
Bash
42 lines
2.0 KiB
Bash
# Sourced by the android/ scripts: picks adb and the target device.
|
|
# ADB adb binary (default: $ANDROID_HOME/platform-tools/adb, else adb on PATH)
|
|
# ANDROID_SERIAL device to use when several are attached (adb honours it itself)
|
|
# An adb server that cannot bind :5037 ("Address already in use" with nothing listening, seen on this
|
|
# Mac after sleep) is retried on :5038 through ANDROID_ADB_SERVER_PORT.
|
|
SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}"
|
|
PKG=org.metin2port.client
|
|
if [ -z "${ADB:-}" ]; then
|
|
if [ -x "$SDK/platform-tools/adb" ]; then ADB="$SDK/platform-tools/adb"; else ADB="$(command -v adb || true)"; fi
|
|
fi
|
|
[ -n "$ADB" ] || { echo "adb not found (install Android platform-tools or set ADB)" >&2; return 1 2>/dev/null || exit 1; }
|
|
if ! "$ADB" start-server >/dev/null 2>&1; then
|
|
export ANDROID_ADB_SERVER_PORT=5038
|
|
"$ADB" start-server >/dev/null 2>&1 || { echo "adb server does not start on :5037 or :5038" >&2; return 1 2>/dev/null || exit 1; }
|
|
echo "adb: :5037 unusable, using :5038"
|
|
fi
|
|
export ADB
|
|
|
|
# adb_device: sets DEVICE to the one ready device (or ANDROID_SERIAL) and returns 0; returns 1 with a
|
|
# message when none is ready (unauthorized / offline devices are named so the user can fix them).
|
|
adb_device() {
|
|
local ready others
|
|
ready=$("$ADB" devices | awk 'NR > 1 && $2 == "device" { print $1 }')
|
|
others=$("$ADB" devices | awk 'NR > 1 && NF >= 2 && $2 != "device" { print $1 " (" $2 ")" }')
|
|
if [ -n "${ANDROID_SERIAL:-}" ]; then
|
|
if printf '%s\n' "$ready" | grep -qxF "$ANDROID_SERIAL"; then DEVICE="$ANDROID_SERIAL"; return 0; fi
|
|
echo "device $ANDROID_SERIAL is not ready" >&2
|
|
return 1
|
|
fi
|
|
case $(printf '%s' "$ready" | grep -c .) in
|
|
1) DEVICE="$ready"; export ANDROID_SERIAL="$DEVICE"; return 0 ;;
|
|
0)
|
|
if [ -n "$others" ]; then
|
|
echo "device attached but not ready: $others (unlock the phone and allow USB debugging)" >&2
|
|
else
|
|
echo "no Android device attached" >&2
|
|
fi
|
|
return 1 ;;
|
|
*) echo "several devices attached, pick one with ANDROID_SERIAL:" $ready >&2; return 1 ;;
|
|
esac
|
|
}
|