feat(build): 添加本地编译脚本,绕过沙箱限制

This commit is contained in:
2026-07-17 17:21:25 +08:00
parent 58eefc88c6
commit a336734897

56
build_apk.ps1 Normal file
View File

@@ -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
}