param([switch]$WithEmulator) $ErrorActionPreference = 'Stop' . (Join-Path $PSScriptRoot 'android-env.ps1') foreach ($taskRequiredPath in @((Join-Path $env:JAVA_HOME 'bin/java.exe'), (Join-Path $env:ANDROID_HOME 'cmdline-tools/latest/bin/sdkmanager.bat'))) { if (-not (Test-Path -LiteralPath $taskRequiredPath)) { throw "Missing tool: $taskRequiredPath" } } $taskLicenseLog = Join-Path $taskToolRoot 'android-license-review.txt' 1..100 | ForEach-Object { 'y' } | & sdkmanager.bat "--sdk_root=$env:ANDROID_HOME" --licenses *> $taskLicenseLog if ($LASTEXITCODE -ne 0) { throw "SDK license setup failed; inspect $taskLicenseLog" } Get-Content -LiteralPath $taskLicenseLog -Tail 3 $taskPackages = @('platform-tools', 'platforms/android-36', 'build-tools/36.0.0', 'cmake/3.22.1', 'ndk/28.2.13676358') if ($WithEmulator) { $taskPackages += @('emulator', 'system-images/android-36/google_apis/x86_64') } $taskInstallLog = Join-Path $taskToolRoot 'android-sdk-install.txt' Write-Output ('Installing Android SDK components: ' + ($taskPackages -join ', ')) # Google's current native CLI avoids the legacy Java downloader's stalled socket. & android.exe --no-metrics "--sdk=$env:ANDROID_HOME" sdk install @taskPackages *> $taskInstallLog if ($LASTEXITCODE -ne 0) { Get-Content -LiteralPath $taskInstallLog -Tail 20; throw 'Android SDK installation failed.' } Get-Content -LiteralPath $taskInstallLog -Tail 5 Write-Output 'Android SDK components installed.'