-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-android.sh
More file actions
executable file
Β·141 lines (118 loc) Β· 4.92 KB
/
run-android.sh
File metadata and controls
executable file
Β·141 lines (118 loc) Β· 4.92 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}π€ Airship .NET MAUI Android Sample Runner${NC}"
echo "==========================================="
# Parse command line arguments
FAST_BUILD=false
if [[ "$1" == "--fast" ]]; then
FAST_BUILD=true
echo "π Fast build requested - skipping clean"
fi
# Check if we're in the right directory
if [ ! -f "MauiSample.csproj" ]; then
echo -e "${RED}β Error: MauiSample.csproj not found. Please run this script from the MauiSample directory.${NC}"
exit 1
fi
# Check UseProjectReferences setting
USE_PROJECT_REFS=$(grep -o '<UseProjectReferences>.*</UseProjectReferences>' MauiSample.csproj | sed 's/<[^>]*>//g')
if [ "$USE_PROJECT_REFS" = "true" ]; then
echo -e "${GREEN}β
Using project references (development mode)${NC}"
echo " SDK changes will be built automatically with the sample app"
else
echo -e "${YELLOW}β οΈ Using NuGet packages${NC}"
echo " To use project references for development, set UseProjectReferences=true in MauiSample.csproj"
# Build the native bindings first if using packages
echo -e "${YELLOW}π¨ Building native Android bindings...${NC}"
cd ..
if ! ./gradlew :binderator:build; then
echo -e "${RED}β Error: Failed to build native bindings${NC}"
exit 1
fi
echo -e "${GREEN}β
Native bindings built successfully${NC}"
# Return to MauiSample directory
cd MauiSample
fi
# Check if any device is connected
if ! adb devices | grep -q "device$"; then
echo -e "${RED}β No Android device detected. Please start an emulator or connect a device.${NC}"
exit 1
fi
# Clean previous builds (skip if --fast)
if [[ "$FAST_BUILD" != "true" ]]; then
echo -e "${YELLOW}π§Ή Cleaning previous builds...${NC}"
dotnet clean -f net10.0-android
fi
# Build the app
echo -e "${YELLOW}π¨ Building Android APK...${NC}"
if ! dotnet build -f net10.0-android -p:NoWarn=NU1608 -v quiet --nologo; then
echo -e "${RED}β Error: Failed to build Android APK${NC}"
exit 1
fi
# Uninstall existing app to ensure clean state
echo -e "${YELLOW}ποΈ Uninstalling existing app...${NC}"
adb uninstall com.urbanairship.sample 2>/dev/null || true
# Install the new APK
echo -e "${YELLOW}π¦ Installing APK...${NC}"
if ! adb install -r bin/Debug/net10.0-android/com.urbanairship.sample-Signed.apk; then
echo -e "${RED}β Error: Failed to install APK${NC}"
exit 1
fi
# Clear previous logs
adb logcat -c
echo -e "${YELLOW}π Launching app...${NC}"
# Launch the app - Try multiple methods
echo "Attempting to launch app..."
# Method 1: Try with monkey (most common)
if adb shell monkey -p com.urbanairship.sample -c android.intent.category.LAUNCHER 1 > /dev/null 2>&1; then
echo -e "${GREEN}β
App launched successfully with monkey${NC}"
else
# Method 2: Try with am start using common MAUI activity name
if adb shell am start -n com.urbanairship.sample/crc64ffe6b59f69e5ae4a.MainActivity > /dev/null 2>&1; then
echo -e "${GREEN}β
App launched successfully with am start${NC}"
else
# Method 3: Try launching by package name only
if adb shell am start --user 0 $(adb shell cmd package resolve-activity --brief com.urbanairship.sample | tail -n 1) > /dev/null 2>&1; then
echo -e "${GREEN}β
App launched successfully${NC}"
else
echo -e "${YELLOW}β οΈ Could not auto-launch app. Please launch it manually from the device.${NC}"
echo -e "${GREEN}App is installed and ready to use.${NC}"
fi
fi
fi
echo -e "${GREEN}π App deployed and running successfully!${NC}"
echo ""
echo -e "${GREEN}π Streaming device logs (Press Ctrl+C to stop)...${NC}"
echo "========================================"
echo ""
# Create log directory with PST timestamp
LOG_BASE_DIR="Sample Run Logs"
mkdir -p "$LOG_BASE_DIR"
# Get PST timestamp (TZ=America/Los_Angeles ensures PST/PDT)
PST_TIMESTAMP=$(TZ=America/Los_Angeles date +"%Y-%m-%d_%H-%M-%S_PST")
LOG_DIR="$LOG_BASE_DIR/$PST_TIMESTAMP"
mkdir -p "$LOG_DIR"
# Create log file
LOG_FILE="$LOG_DIR/logcat.log"
echo -e "${YELLOW}π Logging to directory: $LOG_DIR${NC}"
echo -e "${YELLOW} Device logs: logcat.log${NC}"
echo ""
# Stream logs with filtering for our app and Airship
# - Using Info level (I) instead of Verbose (V) for less noise
# - brief format for cleaner output
# - AndroidRuntime:E to catch crashes
# Tee to both console and file, with colors added for terminal
RESET='\033[0m'
adb logcat -v brief com.urbanairship.sample:I Airship:I UALib:I AndroidRuntime:E *:S 2>&1 | \
while IFS= read -r line; do
case "$line" in
I/*) echo -e "${GREEN}${line}${RESET}" ;;
D/*) echo -e "\033[0;36m${line}${RESET}" ;;
W/*) echo -e "${YELLOW}${line}${RESET}" ;;
E/*) echo -e "${RED}${line}${RESET}" ;;
*) echo "$line" ;;
esac
done | tee "$LOG_FILE"