sevenx_engine 0.2.11

Engine de jogos 2D/3D completa com suporte Android, física, áudio, partículas, tilemap, UI, eventos e sistema 3D avançado com PBR.
Documentation
# SevenX Engine - Android Build Script
# Compila e instala APK no dispositivo Android

param(
    [string]$example = "android_test",
    [string]$target = "aarch64-linux-android",
    [switch]$debug = $false
)

$ErrorActionPreference = "Stop"

Write-Host ""
Write-Host "🤖 SevenX Engine - Android Builder" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""

# Verificar Rust
Write-Host "🔍 Checking Rust installation..." -ForegroundColor Yellow
if (!(Get-Command cargo -ErrorAction SilentlyContinue)) {
    Write-Host "❌ Rust not found! Install from https://rustup.rs" -ForegroundColor Red
    exit 1
}
Write-Host "✅ Rust found" -ForegroundColor Green

# Verificar cargo-apk
Write-Host "🔍 Checking cargo-apk..." -ForegroundColor Yellow
if (!(Get-Command cargo-apk -ErrorAction SilentlyContinue)) {
    Write-Host "⚠️  cargo-apk not found. Installing..." -ForegroundColor Yellow
    cargo install cargo-apk
    if ($LASTEXITCODE -ne 0) {
        Write-Host "❌ Failed to install cargo-apk" -ForegroundColor Red
        exit 1
    }
}
Write-Host "✅ cargo-apk found" -ForegroundColor Green

# Verificar target
Write-Host "🔍 Checking Android target: $target..." -ForegroundColor Yellow
$targets = rustup target list --installed
if ($targets -notcontains $target) {
    Write-Host "⚠️  Target $target not installed. Installing..." -ForegroundColor Yellow
    rustup target add $target
    if ($LASTEXITCODE -ne 0) {
        Write-Host "❌ Failed to install target" -ForegroundColor Red
        exit 1
    }
}
Write-Host "✅ Target $target installed" -ForegroundColor Green

# Verificar ADB
Write-Host "🔍 Checking ADB..." -ForegroundColor Yellow
if (!(Get-Command adb -ErrorAction SilentlyContinue)) {
    Write-Host "❌ ADB not found!" -ForegroundColor Red
    Write-Host "   Install Android SDK and add to PATH" -ForegroundColor Yellow
    Write-Host "   Download: https://developer.android.com/studio" -ForegroundColor Yellow
    exit 1
}
Write-Host "✅ ADB found" -ForegroundColor Green

# Verificar dispositivo conectado
Write-Host "🔍 Checking connected devices..." -ForegroundColor Yellow
$devicesOutput = adb devices
$devices = $devicesOutput | Select-String "device$" | Where-Object { $_ -notmatch "List of devices" }

if ($devices.Count -eq 0) {
    Write-Host "❌ No Android device connected!" -ForegroundColor Red
    Write-Host ""
    Write-Host "📱 Connect your device and:" -ForegroundColor Yellow
    Write-Host "   1. Enable Developer Options" -ForegroundColor Yellow
    Write-Host "   2. Enable USB Debugging" -ForegroundColor Yellow
    Write-Host "   3. Connect via USB" -ForegroundColor Yellow
    Write-Host "   4. Accept USB debugging permission" -ForegroundColor Yellow
    Write-Host ""
    Write-Host "   Then run: adb devices" -ForegroundColor Yellow
    exit 1
}

Write-Host "✅ Device connected:" -ForegroundColor Green
$devices | ForEach-Object { Write-Host "   $_" -ForegroundColor Cyan }

# Verificar se exemplo existe
$examplePath = "examples/$example.rs"
if (!(Test-Path $examplePath)) {
    Write-Host "❌ Example not found: $examplePath" -ForegroundColor Red
    Write-Host ""
    Write-Host "Available examples:" -ForegroundColor Yellow
    Get-ChildItem examples/*.rs | ForEach-Object { 
        Write-Host "   - $($_.BaseName)" -ForegroundColor Cyan 
    }
    exit 1
}
Write-Host "✅ Example found: $example" -ForegroundColor Green

Write-Host ""
Write-Host "🔨 Building APK..." -ForegroundColor Yellow
Write-Host "   Example: $example" -ForegroundColor Cyan
Write-Host "   Target: $target" -ForegroundColor Cyan
Write-Host "   Mode: $(if ($debug) { 'Debug' } else { 'Release' })" -ForegroundColor Cyan
Write-Host ""

# Compilar
$buildArgs = @("apk", "build", "--example", $example, "--target", $target)
if (!$debug) {
    $buildArgs += "--release"
}

$startTime = Get-Date
& cargo $buildArgs

if ($LASTEXITCODE -ne 0) {
    Write-Host ""
    Write-Host "❌ Build failed!" -ForegroundColor Red
    Write-Host ""
    Write-Host "💡 Possíveis soluções:" -ForegroundColor Yellow
    Write-Host "   1. Se o erro for 'Platform XX is not installed':" -ForegroundColor Yellow
    Write-Host "      - Abra Android Studio → Tools → SDK Manager" -ForegroundColor Cyan
    Write-Host "      - Aba 'SDK Platforms' → Marque a plataforma necessária" -ForegroundColor Cyan
    Write-Host "      - Ou leia: CORRIGIR_ERRO_PLATFORM.md" -ForegroundColor Cyan
    Write-Host ""
    Write-Host "   2. Se o erro for 'NDK not found':" -ForegroundColor Yellow
    Write-Host "      - Execute: .\configurar-android.ps1" -ForegroundColor Cyan
    Write-Host ""
    Write-Host "   3. Para mais ajuda:" -ForegroundColor Yellow
    Write-Host "      - Execute: .\verificar-setup.ps1" -ForegroundColor Cyan
    Write-Host ""
    exit 1
}

$buildTime = (Get-Date) - $startTime
Write-Host ""
Write-Host "✅ Build successful! (took $($buildTime.TotalSeconds.ToString('0.0'))s)" -ForegroundColor Green

# Localizar APK
$mode = if ($debug) { "debug" } else { "release" }
$apkPath = "target/$target/$mode/apk/examples/$example.apk"

if (!(Test-Path $apkPath)) {
    Write-Host "❌ APK not found at: $apkPath" -ForegroundColor Red
    exit 1
}

$apkSize = (Get-Item $apkPath).Length / 1MB
Write-Host "📦 APK size: $($apkSize.ToString('0.00')) MB" -ForegroundColor Cyan
Write-Host "📍 APK location: $apkPath" -ForegroundColor Cyan

Write-Host ""
Write-Host "📲 Installing on device..." -ForegroundColor Yellow

# Desinstalar versão antiga (se existir)
$packageName = "com.sevenx.engine"
adb shell pm list packages | Select-String $packageName | Out-Null
if ($LASTEXITCODE -eq 0) {
    Write-Host "   Uninstalling old version..." -ForegroundColor Yellow
    adb uninstall $packageName 2>$null | Out-Null
}

# Instalar
adb install -r $apkPath

if ($LASTEXITCODE -ne 0) {
    Write-Host ""
    Write-Host "❌ Installation failed!" -ForegroundColor Red
    Write-Host ""
    Write-Host "Try manually:" -ForegroundColor Yellow
    Write-Host "   adb install -r $apkPath" -ForegroundColor Cyan
    exit 1
}

Write-Host ""
Write-Host "✅ Installation successful!" -ForegroundColor Green
Write-Host ""
Write-Host "🎮 Open the app on your device!" -ForegroundColor Cyan
Write-Host ""

# Tentar iniciar o app
Write-Host "🚀 Launching app..." -ForegroundColor Yellow
adb shell monkey -p $packageName -c android.intent.category.LAUNCHER 1 2>$null | Out-Null

if ($LASTEXITCODE -eq 0) {
    Write-Host "✅ App launched!" -ForegroundColor Green
} else {
    Write-Host "⚠️  Could not auto-launch. Open manually on device." -ForegroundColor Yellow
}

Write-Host ""
Write-Host "📊 View logs with:" -ForegroundColor Cyan
Write-Host "   adb logcat | findstr SevenX" -ForegroundColor White
Write-Host ""
Write-Host "✨ Done!" -ForegroundColor Green
Write-Host ""