# =========================
# ANDROID STUDIO LAB INSTALLER
# =========================
$ErrorActionPreference = "SilentlyContinue"
$basePath = "C:\Android"
$sdkPath = "C:\Android\Sdk"
$installPath = "C:\Program Files\Android\Android Studio"
$installerFile = "$env:TEMP\android-studio.exe"
Write-Host "=== ANDROID STUDIO INSTALLER ===" -ForegroundColor Cyan
# =========================
# CHECK ADMIN
# =========================
if (-not ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "Execute como ADMINISTRADOR!" -ForegroundColor Red
exit
}
# =========================
# CRIAR PASTAS
# =========================
Write-Host "[1/5] Criando diretorios..."
New-Item -ItemType Directory -Force -Path $basePath | Out-Null
New-Item -ItemType Directory -Force -Path $sdkPath | Out-Null
# =========================
# REMOVER VERSÕES ANTIGAS
# =========================
Write-Host "[2/5] Verificando versoes antigas..."
$keys = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
foreach ($k in $keys) {
Get-ItemProperty $k |
Where-Object {
$_.DisplayName -and $_.DisplayName -like "*Android Studio*"
} |
ForEach-Object {
Write-Host "Removendo: $($_.DisplayName)"
try {
if ($_.UninstallString) {
Start-Process "cmd.exe" -ArgumentList "/c $($_.UninstallString) /S" -Wait
}
} catch {}
}
}
# Remove pastas antigas
Remove-Item $installPath -Recurse -Force
# =========================
# DOWNLOAD
# =========================
Write-Host "[3/5] Baixando Android Studio..."
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (Get-Command wget.exe -ErrorAction SilentlyContinue) {
& wget.exe $installerUrl -O $installerFile
}
else {
Invoke-WebRequest -Uri $installerUrl -OutFile $installerFile -UseBasicParsing
}
if (!(Test-Path $installerFile)) {
throw "Falha no download"
}
Write-Host "Download OK"
}
catch {
Write-Host "Erro no download: $($_.Exception.Message)" -ForegroundColor Red
exit
}
# =========================
# INSTALAÇÃO
# =========================
Write-Host "[4/5] Instalando Android Studio..."
Start-Process -FilePath $installerFile -ArgumentList "/S" -Wait
# =========================
# CONFIGURAÇÃO GLOBAL SDK
# =========================
Write-Host "[5/5] Configurando SDK global..."
[Environment]::SetEnvironmentVariable("ANDROID_HOME", $sdkPath, "Machine")
[Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", $sdkPath, "Machine")
$path = [Environment]::GetEnvironmentVariable("Path", "Machine")
$androidPaths = "$sdkPath\platform-tools;$sdkPath\tools;$sdkPath\emulator"
if ($path -notlike "*platform-tools*") {
[Environment]::SetEnvironmentVariable("Path", "$path;$androidPaths", "Machine")
}
# =========================
# FINAL
# =========================
Write-Host "=== INSTALAÇÃO CONCLUÍDA ===" -ForegroundColor Green
Write-Host "SDK: $sdkPath"
Write-Host "Android Studio instalado."