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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# Script de Instalação Android - SevenX Engine
# Instala APK no dispositivo correto quando há múltiplos dispositivos
Write-Host "📱 SevenX Engine - Instalador Android" -ForegroundColor Cyan
Write-Host "======================================" -ForegroundColor Cyan
Write-Host ""
# Verifica se adb está disponível
if (!(Get-Command adb -ErrorAction SilentlyContinue)) {
Write-Host "❌ ADB não encontrado!" -ForegroundColor Red
Write-Host "Instale o Android SDK Platform Tools" -ForegroundColor Yellow
exit 1
}
# Lista dispositivos conectados
Write-Host "🔍 Procurando dispositivos..." -ForegroundColor Yellow
$devices = adb devices | Select-String -Pattern "^\w+" | Where-Object { $_ -notmatch "List of devices" }
if ($devices.Count -eq 0) {
Write-Host "❌ Nenhum dispositivo conectado!" -ForegroundColor Red
Write-Host ""
Write-Host "Conecte seu dispositivo Android via USB e:" -ForegroundColor Yellow
Write-Host "1. Ative 'Depuração USB' nas opções de desenvolvedor" -ForegroundColor White
Write-Host "2. Autorize o computador no dispositivo" -ForegroundColor White
exit 1
}
Write-Host ""
Write-Host "📱 Dispositivos encontrados:" -ForegroundColor Green
Write-Host ""
$deviceList = @()
$index = 1
foreach ($line in $devices) {
$parts = $line.ToString().Split("`t")
if ($parts.Count -ge 2) {
$deviceId = $parts[0].Trim()
$status = $parts[1].Trim()
if ($status -eq "device") {
# Obter informações do dispositivo
$model = (adb -s $deviceId shell getprop ro.product.model 2>$null).Trim()
$android = (adb -s $deviceId shell getprop ro.build.version.release 2>$null).Trim()
if (!$model) { $model = "Dispositivo Desconhecido" }
if (!$android) { $android = "?" }
$deviceInfo = @{
Index = $index
Id = $deviceId
Model = $model
Android = $android
}
$deviceList += $deviceInfo
Write-Host "$index. $model" -ForegroundColor White
Write-Host " ID: $deviceId" -ForegroundColor Gray
Write-Host " Android: $android" -ForegroundColor Gray
Write-Host ""
$index++
}
}
}
if ($deviceList.Count -eq 0) {
Write-Host "❌ Nenhum dispositivo autorizado encontrado!" -ForegroundColor Red
Write-Host "Verifique se você autorizou a depuração USB no dispositivo" -ForegroundColor Yellow
exit 1
}
# Selecionar dispositivo
$selectedDevice = $null
if ($deviceList.Count -eq 1) {
$selectedDevice = $deviceList[0]
Write-Host "✅ Usando dispositivo: $($selectedDevice.Model)" -ForegroundColor Green
} else {
Write-Host "Escolha o dispositivo (1-$($deviceList.Count)):" -ForegroundColor Cyan
$choice = Read-Host "Digite o número"
$choiceNum = [int]$choice
if ($choiceNum -lt 1 -or $choiceNum -gt $deviceList.Count) {
Write-Host "❌ Escolha inválida!" -ForegroundColor Red
exit 1
}
$selectedDevice = $deviceList[$choiceNum - 1]
Write-Host "✅ Dispositivo selecionado: $($selectedDevice.Model)" -ForegroundColor Green
}
Write-Host ""
Write-Host "======================================" -ForegroundColor Cyan
# Verificar APKs disponíveis
Write-Host ""
Write-Host "📦 Procurando APKs..." -ForegroundColor Yellow
# cargo-apk coloca os APKs em target\{debug|release}\apk\examples\
$apkPaths = @(
"target\release\apk\examples\android_test.apk",
"target\release\apk\examples\android_complete.apk",
"target\debug\apk\examples\android_test.apk",
"target\debug\apk\examples\android_complete.apk"
)
$availableApks = @()
$apkIndex = 1
foreach ($path in $apkPaths) {
if (Test-Path $path) {
$fileInfo = Get-Item $path
$sizeMB = [math]::Round($fileInfo.Length / 1MB, 2)
$buildType = if ($path -match "\\release\\") { "Release" } else { "Debug" }
$apkInfo = @{
Index = $apkIndex
Path = $path
Name = $fileInfo.BaseName
Size = $sizeMB
BuildType = $buildType
}
$availableApks += $apkInfo
Write-Host "$apkIndex. $($apkInfo.Name) [$($apkInfo.BuildType)]" -ForegroundColor White
Write-Host " Tamanho: $($apkInfo.Size) MB" -ForegroundColor Gray
Write-Host " Path: $path" -ForegroundColor Gray
Write-Host ""
$apkIndex++
}
}
if ($availableApks.Count -eq 0) {
Write-Host "❌ Nenhum APK encontrado!" -ForegroundColor Red
Write-Host ""
Write-Host "Execute primeiro:" -ForegroundColor Yellow
Write-Host " .\build-android-complete.ps1" -ForegroundColor White
exit 1
}
# Selecionar APK
$selectedApk = $null
if ($availableApks.Count -eq 1) {
$selectedApk = $availableApks[0]
Write-Host "✅ Usando APK: $($selectedApk.Name)" -ForegroundColor Green
} else {
Write-Host "Escolha o APK (1-$($availableApks.Count)):" -ForegroundColor Cyan
$choice = Read-Host "Digite o número"
$choiceNum = [int]$choice
if ($choiceNum -lt 1 -or $choiceNum -gt $availableApks.Count) {
Write-Host "❌ Escolha inválida!" -ForegroundColor Red
exit 1
}
$selectedApk = $availableApks[$choiceNum - 1]
Write-Host "✅ APK selecionado: $($selectedApk.Name)" -ForegroundColor Green
}
Write-Host ""
Write-Host "======================================" -ForegroundColor Cyan
Write-Host ""
# Verificar se já está instalado
Write-Host "🔍 Verificando instalação existente..." -ForegroundColor Yellow
$packageName = "com.sevenx.engine"
$installed = adb -s $selectedDevice.Id shell pm list packages | Select-String $packageName
if ($installed) {
Write-Host "⚠️ Aplicativo já instalado" -ForegroundColor Yellow
Write-Host "Desinstalando versão antiga..." -ForegroundColor Yellow
adb -s $selectedDevice.Id uninstall $packageName 2>$null
Start-Sleep -Seconds 1
}
# Instalar APK
Write-Host ""
Write-Host "📲 Instalando APK..." -ForegroundColor Cyan
Write-Host " Dispositivo: $($selectedDevice.Model)" -ForegroundColor White
Write-Host " APK: $($selectedApk.Name)" -ForegroundColor White
Write-Host ""
$installResult = adb -s $selectedDevice.Id install -r $selectedApk.Path 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ APK instalado com sucesso!" -ForegroundColor Green
Write-Host ""
# Tentar iniciar o app
Write-Host "🚀 Iniciando aplicativo..." -ForegroundColor Cyan
adb -s $selectedDevice.Id shell am start -n "$packageName/.MainActivity" 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Aplicativo iniciado!" -ForegroundColor Green
} else {
Write-Host "⚠️ Inicie manualmente no dispositivo" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "======================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "📱 Comandos úteis:" -ForegroundColor Cyan
Write-Host ""
Write-Host "Ver logs:" -ForegroundColor White
Write-Host " adb -s $($selectedDevice.Id) logcat | Select-String 'SevenX'" -ForegroundColor Yellow
Write-Host ""
Write-Host "Desinstalar:" -ForegroundColor White
Write-Host " adb -s $($selectedDevice.Id) uninstall $packageName" -ForegroundColor Yellow
Write-Host ""
Write-Host "Reiniciar app:" -ForegroundColor White
Write-Host " adb -s $($selectedDevice.Id) shell am start -n '$packageName/.MainActivity'" -ForegroundColor Yellow
Write-Host ""
} else {
Write-Host "❌ Falha na instalação!" -ForegroundColor Red
Write-Host ""
Write-Host "Erro:" -ForegroundColor Yellow
Write-Host $installResult -ForegroundColor Red
Write-Host ""
Write-Host "Possíveis soluções:" -ForegroundColor Yellow
Write-Host "1. Verifique se há espaço suficiente no dispositivo" -ForegroundColor White
Write-Host "2. Desinstale manualmente versões antigas" -ForegroundColor White
Write-Host "3. Verifique se a depuração USB está ativa" -ForegroundColor White
Write-Host "4. Tente reiniciar o dispositivo" -ForegroundColor White
exit 1
}
Write-Host "✅ Instalação completa!" -ForegroundColor Green