Files
ScrcpyForAndroid/build_apk.ps1
zhimin.liu ca089428b8 feat(system):1.调整编译脚本. 2.用以下指令开启系统允许该程序浮窗功能:
adb shell appops set io.github.miuzarte.scrcpyforandroid SYSTEM_ALERT_WINDOW allow
2026-07-17 19:15:05 +08:00

62 lines
2.1 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}