diff --git a/build_apk.ps1 b/build_apk.ps1 new file mode 100644 index 0000000..51a3f8f --- /dev/null +++ b/build_apk.ps1 @@ -0,0 +1,56 @@ +param( + [ValidateSet("debug", "release")] + [string]$BuildType = "release" +) + +$ErrorActionPreference = "Stop" +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path + +# JDK 配置 +$JDK_HOME = "C:\Program Files\Eclipse Adoptium\jdk-11.0.31.11-hotspot" +$env:JAVA_HOME = $JDK_HOME +$env:PATH = "$JDK_HOME\bin;$env:PATH" + +Write-Host "========================================" -ForegroundColor Cyan +Write-Host " ScrcpyForAndroid APK Builder" -ForegroundColor Cyan +Write-Host " Build Type: $BuildType" -ForegroundColor Yellow +Write-Host " JDK: $JDK_HOME" -ForegroundColor Gray +Write-Host "========================================" -ForegroundColor Cyan +Write-Host "" + +Push-Location $ScriptDir + +try { + if ($BuildType -eq "release") { + Write-Host ">>> Building Release APK..." -ForegroundColor Green + .\gradlew.bat :app:assembleRelease --console=plain + $apkDir = "app\build\outputs\apk\release" + } else { + Write-Host ">>> Building Debug APK..." -ForegroundColor Green + .\gradlew.bat :app:assembleDebug --console=plain + $apkDir = "app\build\outputs\apk\debug" + } + + if ($LASTEXITCODE -eq 0) { + Write-Host "" + Write-Host "========================================" -ForegroundColor Green + Write-Host " BUILD SUCCESSFUL!" -ForegroundColor Green + Write-Host "========================================" -ForegroundColor Green + Write-Host "" + + if (Test-Path $apkDir) { + Get-ChildItem "$apkDir\*.apk" | ForEach-Object { + $sizeMB = [math]::Round($_.Length / 1MB, 1) + Write-Host " $($_.Name) ($sizeMB MB)" -ForegroundColor White + } + Write-Host "" + Write-Host " Output: $ScriptDir\$apkDir" -ForegroundColor Gray + } + } else { + Write-Host "" + Write-Host "BUILD FAILED (exit code: $LASTEXITCODE)" -ForegroundColor Red + exit $LASTEXITCODE + } +} finally { + Pop-Location +}