Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·104 lines (83 loc) · 3.5 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·104 lines (83 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -euo pipefail
APP_PACKAGE="com.example.redacto"
MAIN_ACTIVITY="${APP_PACKAGE}/.MainActivity"
APK_PATH="app/build/outputs/apk/debug/app-debug.apk"
# Local file → device filename mapping (must match ModelVariant enum)
NPU_MODEL_LOCAL="app/src/main/assets/gemma4_npu.litertlm"
NPU_MODEL_DEVICE="/sdcard/Android/data/${APP_PACKAGE}/files/gemma4_npu.litertlm"
GENERIC_MODEL_LOCAL="app/src/main/assets/gemma-4-E2B-it.litertlm"
GENERIC_MODEL_DEVICE="/sdcard/Android/data/${APP_PACKAGE}/files/gemma4.litertlm"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[deploy]${NC} $*"; }
warn() { echo -e "${YELLOW}[deploy]${NC} $*"; }
error() { echo -e "${RED}[deploy]${NC} $*" >&2; exit 1; }
push_model_if_needed() {
local local_path="$1"
local device_path="$2"
local label="$3"
if [[ ! -f "$local_path" ]]; then
warn "$label not found at $local_path — skipping push."
warn "App will show 'Model missing' if $label variant is selected."
return
fi
DEVICE_SIZE=$($ADB shell "stat -c %s '$device_path' 2>/dev/null" 2>/dev/null || echo "0")
LOCAL_SIZE=$(stat --printf="%s" "$local_path" 2>/dev/null || stat -f%z "$local_path" 2>/dev/null || echo "0")
if [[ "$DEVICE_SIZE" -ne "$LOCAL_SIZE" ]]; then
info "Pushing $label to device ($(( LOCAL_SIZE / 1024 / 1024 )) MB, may take a few minutes)..."
$ADB shell "mkdir -p /sdcard/Android/data/${APP_PACKAGE}/files/"
$ADB push "$local_path" "$device_path"
info "$label pushed."
else
info "$label already on device (size matches). Skipping."
fi
}
# --- Locate the S25 device ---
info "Searching for connected Samsung S25..."
ADB_OUTPUT=$(adb devices 2>/dev/null | tail -n +2 | grep -v "^$" || true)
if [[ -z "$ADB_OUTPUT" ]]; then
error "No devices found. Ensure USB debugging is enabled and the S25 is plugged in."
fi
DEVICE_COUNT=$(echo "$ADB_OUTPUT" | wc -l)
SERIAL=""
if [[ "$DEVICE_COUNT" -eq 1 ]]; then
SERIAL=$(echo "$ADB_OUTPUT" | awk '{print $1}')
STATE=$(echo "$ADB_OUTPUT" | awk '{print $2}')
if [[ "$STATE" == "unauthorized" ]]; then
error "Device $SERIAL is unauthorized. Unlock the phone and accept the USB debugging prompt."
fi
info "Found device: $SERIAL"
else
warn "Multiple devices detected:"
echo "$ADB_OUTPUT"
echo ""
read -rp "Enter the S25 serial (from list above): " SERIAL
if [[ -z "$SERIAL" ]]; then
error "No serial provided."
fi
fi
ADB="adb -s $SERIAL"
# Verify device is reachable
$ADB get-state >/dev/null 2>&1 || error "Cannot communicate with device $SERIAL"
info "Device $SERIAL is online."
# --- Build ---
info "Building debug APK..."
./gradlew assembleDebug --quiet || error "Gradle build failed."
info "Build complete: $APK_PATH"
# --- Install ---
info "Installing APK on $SERIAL..."
$ADB install -r "$APK_PATH" || error "APK install failed."
info "Install complete."
# --- Push models ---
push_model_if_needed "$NPU_MODEL_LOCAL" "$NPU_MODEL_DEVICE" "NPU model (SM8750 → gemma4_npu.litertlm)"
push_model_if_needed "$GENERIC_MODEL_LOCAL" "$GENERIC_MODEL_DEVICE" "Generic model (CPU/GPU → gemma4.litertlm)"
# --- Launch ---
info "Launching Redacto..."
$ADB shell am force-stop "$APP_PACKAGE" 2>/dev/null || true
$ADB shell am start -n "$MAIN_ACTIVITY"
info "Done! Redacto is running on $SERIAL."
info "Watch backend: adb -s $SERIAL logcat -s InferenceEngine:I"
info "Watch NPU init: adb -s $SERIAL logcat | grep -E 'InferenceEngine|LiteRt|QNN|Dispatch'"