@@ -294,7 +294,7 @@ jobs:
294294 integration-android :
295295 name : Android emulator integration (${{ matrix.os }})
296296 runs-on : ${{ matrix.os }}
297- timeout-minutes : 50
297+ timeout-minutes : 65
298298 needs :
299299 - client
300300 - packages
@@ -349,7 +349,7 @@ jobs:
349349 - name : Create and boot Android emulator (Windows)
350350 if : runner.os == 'Windows'
351351 shell : pwsh
352- timeout-minutes : 30
352+ timeout-minutes : 45
353353 run : |
354354 $ErrorActionPreference = "Stop"
355355 $sdk = $env:ANDROID_HOME
@@ -375,6 +375,9 @@ jobs:
375375 $avdmanager = Join-Path $toolsBin "avdmanager.bat"
376376 $adb = Join-Path $sdk "platform-tools\adb.exe"
377377 $emulator = Join-Path $sdk "emulator\emulator.exe"
378+ $windowsApi = "30"
379+ $windowsPlatform = "platforms;android-$windowsApi"
380+ $windowsSystemImage = "system-images;android-$windowsApi;google_apis;x86_64"
378381
379382 $yesFile = Join-Path $env:RUNNER_TEMP "android-sdk-yes.txt"
380383 1..200 | ForEach-Object { "y" } | Set-Content -Path $yesFile -Encoding ascii
@@ -393,26 +396,67 @@ jobs:
393396 Write-Host "Accepting Android SDK licenses"
394397 Invoke-AndroidToolWithInput $sdkmanager "--licenses" $yesFile
395398 Write-Host "Installing Android SDK emulator packages"
396- Invoke-AndroidToolWithInput $sdkmanager "--install `"platform-tools`" `"emulator`" `"platforms;android-35`" `"system-images;android-35;google_apis;x86_64`"" $yesFile
399+ Invoke-AndroidToolWithInput $sdkmanager "--install `"platform-tools`" `"emulator`" `"$windowsPlatform`" `"$windowsSystemImage`"" $yesFile
400+ Write-Host "Checking Android emulator acceleration"
401+ & $emulator -accel-check
402+ if ($LASTEXITCODE -ne 0) {
403+ Write-Host "Hosted Windows runner did not report VM acceleration; forcing software acceleration for the CI smoke emulator."
404+ }
397405 Write-Host "Creating Android AVD"
398- Invoke-AndroidToolWithInput $avdmanager "create avd --force --name SimDeck_Pixel_CI --package `"system-images;android-35;google_apis;x86_64 `" --device `"pixel_6`"" $noFile
406+ Invoke-AndroidToolWithInput $avdmanager "create avd --force --name SimDeck_Pixel_CI --package `"$windowsSystemImage `" --device `"pixel_6`"" $noFile
399407
408+ $stdout = Join-Path $env:RUNNER_TEMP "simdeck-android-emulator.out.log"
409+ $stderr = Join-Path $env:RUNNER_TEMP "simdeck-android-emulator.err.log"
400410 $args = @(
401411 "-avd", "SimDeck_Pixel_CI",
402412 "-no-window",
403413 "-no-audio",
404414 "-no-boot-anim",
405415 "-no-snapshot",
406416 "-gpu", "swiftshader_indirect",
407- "-grpc", "8554"
417+ "-grpc", "8554",
418+ "-port", "5554",
419+ "-accel", "off",
420+ "-no-metrics",
421+ "-skip-adb-auth"
408422 )
423+ function Write-EmulatorDiagnostics {
424+ Write-Host "adb devices:"
425+ & $adb devices -l
426+ if (Test-Path $stdout) {
427+ Write-Host "emulator stdout tail:"
428+ Get-Content $stdout -Tail 80
429+ }
430+ if (Test-Path $stderr) {
431+ Write-Host "emulator stderr tail:"
432+ Get-Content $stderr -Tail 120
433+ }
434+ }
409435 Write-Host "Starting Android emulator"
410- $process = Start-Process -FilePath $emulator -ArgumentList $args -PassThru
436+ $process = Start-Process -FilePath $emulator -ArgumentList $args -PassThru -RedirectStandardOutput $stdout -RedirectStandardError $stderr
411437 $process.Id | Out-File -FilePath emulator.pid -Encoding ascii
412- & $adb wait-for-device
413- $deadline = (Get-Date).AddMinutes(12)
438+ $deviceDeadline = (Get-Date).AddMinutes(8)
439+ $deviceSeen = $false
440+ do {
441+ if ($process.HasExited) {
442+ Write-EmulatorDiagnostics
443+ throw "Android emulator exited early with code $($process.ExitCode)."
444+ }
445+ $devices = (& $adb devices)
446+ if ($devices -match "emulator-5554\s+(device|offline)") {
447+ $deviceSeen = $true
448+ break
449+ }
450+ Start-Sleep -Seconds 5
451+ } while ((Get-Date) -lt $deviceDeadline)
452+ if (-not $deviceSeen) {
453+ Write-EmulatorDiagnostics
454+ throw "Android emulator did not appear in adb before the timeout."
455+ }
456+ $deadline = (Get-Date).AddMinutes(20)
414457 do {
415458 if ($process.HasExited) {
459+ Write-EmulatorDiagnostics
416460 throw "Android emulator exited early with code $($process.ExitCode)."
417461 }
418462 $booted = (& $adb shell getprop sys.boot_completed).Trim()
@@ -422,7 +466,7 @@ jobs:
422466 Start-Sleep -Seconds 5
423467 } while ((Get-Date) -lt $deadline)
424468 if ($booted -ne "1") {
425- & $adb devices
469+ Write-EmulatorDiagnostics
426470 throw "Android emulator did not boot before the timeout."
427471 }
428472 & $adb shell settings put global window_animation_scale 0
@@ -449,8 +493,13 @@ jobs:
449493 $adb = Join-Path $sdk "platform-tools\adb.exe"
450494 if (Test-Path $adb) {
451495 & $adb emu kill
496+ if ($LASTEXITCODE -ne 0) {
497+ Write-Host "No Android emulator accepted adb emu kill."
498+ $global:LASTEXITCODE = 0
499+ }
452500 }
453501 }
454502 if (Test-Path emulator.pid) {
455503 Stop-Process -Id (Get-Content emulator.pid) -Force -ErrorAction SilentlyContinue
456504 }
505+ exit 0
0 commit comments