-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeploy-Android.ps1
More file actions
174 lines (151 loc) · 5.57 KB
/
Deploy-Android.ps1
File metadata and controls
174 lines (151 loc) · 5.57 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# DrillDown - Android Deployment Script
# Builds and deploys the APK to connected Android device
Write-Host ""
Write-Host "========================================"
Write-Host " DrillDown - Android Deployment"
Write-Host "========================================"
Write-Host ""
$incrementScript = Join-Path $PSScriptRoot "Increment-Version.ps1"
if (Test-Path $incrementScript) {
Write-Host "Incrementing Android/Desktop version numbers..."
$incrementProcess = Start-Process -FilePath powershell -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File',"$incrementScript",'-Force') -Wait -PassThru -NoNewWindow
if ($incrementProcess.ExitCode -ne 0) {
Write-Host ""
Write-Host "ERROR: Version increment failed. Aborting deployment." -ForegroundColor Red
exit $incrementProcess.ExitCode
}
Write-Host ""
} else {
Write-Host "WARNING: Increment-Version.ps1 not found. Version bump must be done manually." -ForegroundColor Yellow
Write-Host ""
}
# Find ADB
$adbCmd = $null
$adbLocations = @(
"C:\Users\$env:USERNAME\AppData\Local\Android\Sdk\platform-tools\adb.exe",
"C:\Android\Sdk\platform-tools\adb.exe",
"C:\Program Files\Android\Sdk\platform-tools\adb.exe",
"C:\Program Files (x86)\Android\Sdk\platform-tools\adb.exe"
)
# Check if adb is in PATH
try {
$null = Get-Command adb -ErrorAction Stop
$adbCmd = "adb"
Write-Host "ADB found in PATH"
} catch {
Write-Host "ADB not in PATH, searching common locations..."
foreach ($location in $adbLocations) {
if (Test-Path $location) {
$adbCmd = $location
Write-Host "Found at: $adbCmd"
break
}
}
}
if (-not $adbCmd) {
Write-Host ""
Write-Host "ERROR: ADB not found!" -ForegroundColor Red
Write-Host ""
Write-Host "Please install Android SDK and ensure ADB is available."
exit 1
}
# Check for connected device
Write-Host "Checking for connected device..."
$devicesOutput = & $adbCmd devices 2>&1
$devices = $devicesOutput | Select-String "^\w+" | Where-Object { $_ -notmatch "List of" -and $_ -notmatch "^$" }
if (-not $devices) {
Write-Host ""
Write-Host "ERROR: No Android device connected!" -ForegroundColor Red
Write-Host ""
Write-Host "Please:"
Write-Host " 1. Connect your phone via USB cable"
Write-Host " 2. Enable USB Debugging (Settings > Developer options > USB Debugging)"
Write-Host " 3. Run this script again"
exit 1
}
$deviceId = ($devices[0] -split "\s+")[0]
Write-Host "Device found: $deviceId"
Write-Host ""
# Stop Gradle daemons to release file locks
Write-Host "Stopping Gradle daemons..."
& .\gradlew.bat --stop 2>&1 | Out-Null
Start-Sleep -Seconds 2
# Kill any remaining Java processes
Write-Host "Cleaning up processes..."
Stop-Process -Name java -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
# Clean build directories manually
Write-Host "Removing old build artifacts..."
if (Test-Path "android\build") {
Remove-Item -Recurse -Force "android\build" -ErrorAction SilentlyContinue
}
if (Test-Path "gdx-sfx\android\build") {
Remove-Item -Recurse -Force "gdx-sfx\android\build" -ErrorAction SilentlyContinue
}
Start-Sleep -Seconds 1
# Build the APK
Write-Host ""
Write-Host "Building Android APK (Release)..."
Write-Host ""
& .\gradlew.bat android:assembleFullRelease
$buildExit = $LASTEXITCODE
if ($buildExit -ne 0) {
Write-Host ""
Write-Host "BUILD FAILED with exit code $buildExit!" -ForegroundColor Red
Write-Host ""
Write-Host "Troubleshooting:"
Write-Host " - Check gradle.properties for keystore configuration"
Write-Host " - Ensure keystore file exists"
Write-Host " - Run: gradlew --stop (to reset daemon)"
exit 1
}
Write-Host ""
Write-Host "========================================"
Write-Host "BUILD SUCCESSFUL!" -ForegroundColor Green
Write-Host "========================================"
Write-Host ""
# Check if APK exists
$apkPath = "android\build\outputs\apk\full\release\android-full-release.apk"
if (-not (Test-Path $apkPath)) {
Write-Host ""
Write-Host "ERROR: APK not found at $apkPath" -ForegroundColor Red
exit 1
}
# Install the APK
Write-Host "Installing APK to device: $deviceId"
Write-Host ""
Write-Host "Installing/updating app on device..."
$installResult = & $adbCmd install -r $apkPath 2>&1
$success = $installResult -match "Success"
if (-not $success) {
Write-Host ""
Write-Host "Installation failed - attempting to uninstall old version first..." -ForegroundColor Yellow
& $adbCmd uninstall de.dakror.quarry 2>&1 | Out-Null
Start-Sleep -Seconds 2
Write-Host "Retrying installation..."
$installResult = & $adbCmd install $apkPath 2>&1
$success = $installResult -match "Success"
if (-not $success) {
Write-Host ""
Write-Host "INSTALLATION FAILED!" -ForegroundColor Red
Write-Host ""
Write-Host "Possible reasons:"
Write-Host " - Not enough storage on phone"
Write-Host " - USB connection issue"
Write-Host " - Device not authorized"
Write-Host ""
Write-Host "Output: $installResult"
exit 1
}
}
Write-Host ""
Write-Host "========================================"
Write-Host " DEPLOYMENT SUCCESSFUL!" -ForegroundColor Green
Write-Host "========================================"
Write-Host ""
Write-Host "The app is now installed on your phone."
Write-Host ""
Write-Host "IMPORTANT - For next update:"
Write-Host " • Simply run this script again; it auto bumps versionCode/versionName."
Write-Host " • Need to bump versions manually? Run Increment-Version.ps1 by itself."
Write-Host ""