rebreak-monorepo/apps/rebreak-native/install-android.sh

96 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Rebreak Native — Build debug APK + install on connected Android device.
#
# Usage:
# ./install-android.sh # build + install + launch
# ./install-android.sh --no-build # skip Gradle build, just install last APK
# ./install-android.sh --no-launch # install but don't auto-launch
#
# Multi-Device:
# ANDROID_SERIAL=<serial> ./install-android.sh
#
# Wireless-ADB (einmalig):
# adb pair <ip>:<pair-port> # PIN vom Phone-Display eingeben
# adb connect <ip>:<connect-port>
#
# Phone-Setup:
# Einstellungen → Entwickleroptionen → USB-Debugging an
# Beim ersten Connect: "Diesem Computer vertrauen?" → Erlauben
set -euo pipefail
cd "$(dirname "$0")"
PACKAGE="org.rebreak.app"
APK="android/app/build/outputs/apk/debug/app-debug.apk"
SKIP_BUILD=0
LAUNCH=1
while [[ $# -gt 0 ]]; do
case "$1" in
--no-build) SKIP_BUILD=1; shift ;;
--no-launch) LAUNCH=0; shift ;;
-h|--help)
awk '/^#!/{next} /^#/{sub(/^# ?/, ""); print; next} {exit}' "$0"
exit 0 ;;
*) echo "Unbekanntes Flag: $1"; echo " --help für Hilfe"; exit 1 ;;
esac
done
if ! command -v adb >/dev/null 2>&1; then
echo "adb nicht im PATH. Android Platform-Tools installieren:"
echo " brew install --cask android-platform-tools"
exit 1
fi
# Lines that end with literal "device" (excludes "unauthorized", "offline", header).
DEVICE_LINES=$(adb devices | grep -E '[[:space:]]device$' || true)
DEVICE_COUNT=$(printf '%s\n' "$DEVICE_LINES" | grep -c '.' || true)
if [[ "$DEVICE_COUNT" -eq 0 ]]; then
echo "Kein verfügbares Android-Gerät via ADB."
echo ""
adb devices
echo ""
echo "Mögliche Ursachen:"
echo " - USB nicht angeschlossen / Kabel nur Strom (nicht Daten)"
echo " - USB-Debugging auf dem Phone aus"
echo " - 'Diesem Computer vertrauen?' Dialog noch nicht bestätigt → 'unauthorized'"
echo " - Wireless-ADB nicht verbunden → adb connect <ip>:<port>"
exit 1
fi
if [[ "$DEVICE_COUNT" -gt 1 && -z "${ANDROID_SERIAL:-}" ]]; then
echo "Mehrere Geräte verbunden:"
adb devices
echo ""
echo "Eines auswählen via ANDROID_SERIAL:"
echo " ANDROID_SERIAL=<serial> $0"
exit 1
fi
if [[ "$SKIP_BUILD" -eq 0 ]]; then
echo "→ Building debug APK (gradlew assembleDebug)..."
( cd android && ./gradlew assembleDebug --console=plain )
fi
if [[ ! -f "$APK" ]]; then
echo "APK nicht gefunden: $APK"
echo " --no-build weglassen oder Build-Fehler oben prüfen."
exit 1
fi
echo ""
echo "→ Installing $APK..."
adb install -r -d "$APK"
if [[ "$LAUNCH" -eq 1 ]]; then
echo ""
echo "→ Launching $PACKAGE..."
adb shell monkey -p "$PACKAGE" -c android.intent.category.LAUNCHER 1 >/dev/null 2>&1 || {
echo "Launch via monkey schlug fehl — App ist installiert, du kannst sie manuell öffnen."
}
fi
echo ""
echo "Fertig."