用途
environment-setup-bundletool 是一个可选的环境准备技能,目标是从官方 GitHub 发布页安装并验证 bundletool.jar,使 Android App Bundle 工具链在明确需要时可用于 UiAutomator2 或 Espresso 的配置。
主要能力
- 检测宿主操作系统与当前 bundletool 可用性。
- 当 bundletool.jar 已可通过 PATH 解析时,不重复安装,仅验证并报告当前版本。
- 当 PATH 中不存在 bundletool.jar 时,从 https://github.com/google/bundletool/releases 下载最新的 bundletool-all-*.jar 发布资产,并在可用时验证发布资产来源与校验和/签名,然后将其放入 PATH 目录。
- 在 macOS/Linux 与 Windows PowerShell 下分别提供检测、下载、验证命令。
- 报告任务结果,包括解析到的 bundletool.jar 路径、版本输出,以及是否因已存在而跳过安装。
使用方式
技能按以下决策逻辑执行:
- 若宿主操作系统不受支持,停止并请用户在 macOS、Linux 或 Windows 上运行。
- 若用户未明确请求 bundletool 设置,跳过此技能。
- 若 bundletool.jar 已可通过 PATH 解析,不重新安装,验证并报告当前版本。
- 若 PATH 中不存在 bundletool.jar,则下载最新发布资产并放入 PATH 目录。
检测与验证命令示例:
macOS/Linux:
uname -s
command -v bundletool.jar || echo "bundletool.jar not found"
if command -v bundletool.jar >/dev/null 2>&1; then java -jar "$(command -v bundletool.jar)" version; fi
Windows PowerShell:
[System.Environment]::OSVersion.VersionString
$btPath = ($env:Path -split ';' | Where-Object { $_ -and (Test-Path (Join-Path $_ 'bundletool.jar')) } | ForEach-Object { Join-Path $_ 'bundletool.jar' } | Select-Object -First 1)
$btPath
if ($btPath) { java -jar $btPath version }
下载命令示例:
macOS/Linux:
mkdir -p "$HOME/bin"
RELEASE_API="https://api.github.com/repos/google/bundletool/releases/latest"
DOWNLOAD_URL=$(curl -fsSL "$RELEASE_API" | grep -Eo 'https://github.com/google/bundletool/releases/download/[^\"]+/bundletool-all-[^\"]+\.jar' | head -n 1)
test -n "$DOWNLOAD_URL"
curl -fL "$DOWNLOAD_URL" -o "$HOME/bin/bundletool.jar"
chmod +x "$HOME/bin/bundletool.jar"
export PATH="$HOME/bin:$PATH"
Windows PowerShell:
$targetDir = "$HOME\bin"
New-Item -ItemType Directory -Force $targetDir | Out-Null
$release = Invoke-RestMethod "https://api.github.com/repos/google/bundletool/releases/latest"
$asset = $release.assets | Where-Object { $_.name -match '^bundletool-all-.*\.jar$' } | Select-Object -First 1
if (-not $asset) { throw "bundletool release asset not found" }
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile "$targetDir\bundletool.jar"
$currentPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if ($currentPath -notlike "*$targetDir*") {
[Environment]::SetEnvironmentVariable('Path', "$currentPath;$targetDir", 'User')
}
$env:Path = [Environment]::GetEnvironmentVariable('Path', 'User')
验证安装:
macOS/Linux:
command -v bundletool.jar
java -jar "$(command -v bundletool.jar)" version
Windows PowerShell:
$btPath = ($env:Path -split ';' | Where-Object { $_ -and (Test-Path (Join-Path $_ 'bundletool.jar')) } | ForEach-Object { Join-Path $_ 'bundletool.jar' } | Select-Object -First 1)
if (-not $btPath) { throw "bundletool.jar not found in PATH directories" }
$btPath
java -jar $btPath version
适用场景
- 用户明确请求为 UiAutomator2 或 Espresso 配置 bundletool 时。
- 需要在 macOS、Linux 或 Windows 上准备 Android App Bundle 工具链时。
限制
- 该技能为可选技能,仅在用户明确请求 bundletool 设置时运行。
- 安装可选依赖前需询问用户。
- 若需要特权命令,应暂停并提供确切命令供用户执行。
- 不修改无关的 Appium、Android SDK、Java 或 Xcode 配置。
- 完成标准:bundletool.jar 可从 PATH 解析;java -jar <bundletool.jar> version 成功;结果摘要说明是执行了安装还是跳过。
- 需报告的证据包括:宿主操作系统、bundletool 是否已存在或已安装、执行下载时的 GitHub 发布标签与资产 URL、可用时的校验和/签名验证来源、解析到的 bundletool.jar 路径、java -jar <bundletool.jar> version 输出。
- 使用后应报告任何缺失、含糊、过时或导致重试的指令及其章节与建议措辞,但除非被要求,不编辑该技能。