From a33673489772becce51e577d908cd990d9fc8fe2 Mon Sep 17 00:00:00 2001 From: "zhimin.liu" Date: Fri, 17 Jul 2026 17:21:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(build):=20=E6=B7=BB=E5=8A=A0=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E7=BC=96=E8=AF=91=E8=84=9A=E6=9C=AC=EF=BC=8C=E7=BB=95?= =?UTF-8?q?=E8=BF=87=E6=B2=99=E7=AE=B1=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_apk.ps1 | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 build_apk.ps1 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 +}