build: bundle adb platform tools

This commit is contained in:
Your Name committed 2026-06-27 17:59:36 +08:00
1 parent ecbd07cea0
commit f257c4e3fc
11 files changed
+207 -6

No files matched your search

+57
View File
@@ -8,6 +8,7 @@ param(
[switch]$PackExeForce,
[switch]$IncludeLicense,
[switch]$ReuseCache,
[string]$PlatformToolsDir = "",
[string]$UpxDir = ""
)
@@ -185,6 +186,62 @@ foreach ($dir in @("logs", "pic", "state")) {
New-Item -ItemType File -Force (Join-Path $runtimeDir ".keep") | Out-Null
}
$PlatformToolCandidates = @()
if ($PlatformToolsDir) {
$PlatformToolCandidates += $PlatformToolsDir
}
foreach ($envName in @("ANDROID_PLATFORM_TOOLS", "ANDROID_HOME", "ANDROID_SDK_ROOT")) {
$envValue = [Environment]::GetEnvironmentVariable($envName)
if (-not $envValue) {
continue
}
if ($envName -eq "ANDROID_PLATFORM_TOOLS") {
$PlatformToolCandidates += $envValue
} else {
$PlatformToolCandidates += (Join-Path $envValue "platform-tools")
}
}
if ($env:LOCALAPPDATA) {
$PlatformToolCandidates += (Join-Path $env:LOCALAPPDATA "platform-tools")
}
$PlatformToolCandidates += (Join-Path $Root "platform-tools")
$ResolvedPlatformTools = ""
foreach ($candidate in $PlatformToolCandidates) {
if (-not $candidate) {
continue
}
$adbCandidate = Join-Path $candidate "adb.exe"
if (Test-Path $adbCandidate) {
$ResolvedPlatformTools = (Resolve-Path $candidate).Path
break
}
}
if (-not $ResolvedPlatformTools) {
throw "Missing Android platform-tools. Provide -PlatformToolsDir or install it under LOCALAPPDATA\platform-tools."
}
$PlatformToolsTarget = Join-Path $DistRoot "platform-tools"
if (Test-Path $PlatformToolsTarget) {
Remove-Item -LiteralPath $PlatformToolsTarget -Recurse -Force
}
New-Item -ItemType Directory -Force $PlatformToolsTarget | Out-Null
$PlatformToolFiles = @(
"adb.exe",
"AdbWinApi.dll",
"AdbWinUsbApi.dll",
"NOTICE.txt",
"source.properties"
)
foreach ($name in $PlatformToolFiles) {
$src = Join-Path $ResolvedPlatformTools $name
if ($name -in @("adb.exe", "AdbWinApi.dll", "AdbWinUsbApi.dll") -and -not (Test-Path $src)) {
throw "Missing required platform-tools file: $name"
}
if (Test-Path $src) {
Copy-Item -LiteralPath $src -Destination (Join-Path $PlatformToolsTarget $name) -Force
}
}
$licensePath = Join-Path $Root "license.dat"
if ($IncludeLicense -and (Test-Path $licensePath)) {
Copy-Item -LiteralPath $licensePath -Destination (Join-Path $DistRoot "license.dat") -Force