adb shell appops set io.github.miuzarte.scrcpyforandroid SYSTEM_ALERT_WINDOW allow
62 lines
2.1 KiB
PowerShell
62 lines
2.1 KiB
PowerShell
param(
|
||
[ValidateSet("debug", "release")]
|
||
[string]$BuildType = "debug"
|
||
)
|
||
|
||
$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 {
|
||
# 停止旧 daemon(可能被 VS Code JRE 污染),失败也忽略
|
||
Write-Host ">>> Stopping old Gradle daemon..." -ForegroundColor Gray
|
||
.\gradlew.bat --stop 2>$null
|
||
Write-Host ""
|
||
|
||
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
|
||
}
|