feat(android): establish Roubao build baseline
This commit is contained in:
@@ -3,31 +3,68 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
Set-Location -Path $PSScriptRoot
|
||||
|
||||
# T-001 接入真实工程后替换。未配置时主动失败,防止把占位命令当成有效基线。
|
||||
$InstallCmd = "__REPLACE_AFTER_T001__"
|
||||
$VerifyCmd = "__REPLACE_AFTER_T001__"
|
||||
$StartCmd = "__REPLACE_AFTER_T001__"
|
||||
|
||||
foreach ($entry in @{
|
||||
InstallCmd = $InstallCmd
|
||||
VerifyCmd = $VerifyCmd
|
||||
StartCmd = $StartCmd
|
||||
}.GetEnumerator()) {
|
||||
if ($entry.Value -like "__REPLACE_*") {
|
||||
[Console]::Error.WriteLine(
|
||||
"项目尚未完成 T-001;请配置 $($entry.Key),并同步 docs/03-tech-stack.md 和 docs/current-state.md。"
|
||||
)
|
||||
exit 2
|
||||
}
|
||||
$sdkRoot = if ($env:ANDROID_SDK_ROOT) {
|
||||
$env:ANDROID_SDK_ROOT
|
||||
} elseif ($env:ANDROID_HOME) {
|
||||
$env:ANDROID_HOME
|
||||
} else {
|
||||
Join-Path $env:LOCALAPPDATA "Android\Sdk"
|
||||
}
|
||||
|
||||
Write-Host "==> 当前目录: $($PWD.Path)"
|
||||
Write-Host "==> 同步依赖"
|
||||
Invoke-Expression $InstallCmd
|
||||
Write-Host "==> 运行基础验证"
|
||||
Invoke-Expression $VerifyCmd
|
||||
Write-Host "==> 启动命令: $StartCmd"
|
||||
$gradle = Join-Path $PSScriptRoot "android-buyer\gradlew.bat"
|
||||
$adb = Join-Path $sdkRoot "platform-tools\adb.exe"
|
||||
$apk = Join-Path $PSScriptRoot "android-buyer\app\build\outputs\apk\debug\app-debug.apk"
|
||||
|
||||
if (-not (Test-Path -LiteralPath $gradle)) {
|
||||
throw "缺少 Android Gradle Wrapper: $gradle"
|
||||
}
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $sdkRoot "platforms\android-34"))) {
|
||||
throw "缺少 Android SDK 34,请设置 ANDROID_SDK_ROOT 或 ANDROID_HOME。"
|
||||
}
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $sdkRoot "build-tools\34.0.0"))) {
|
||||
throw "缺少 Android SDK Build Tools 34.0.0。"
|
||||
}
|
||||
if (-not (Get-Command java -ErrorAction SilentlyContinue)) {
|
||||
throw "缺少 JDK 17,java 不在 PATH 中。"
|
||||
}
|
||||
$javaVersion = (& java -version 2>&1) -join "`n"
|
||||
if ($javaVersion -notmatch 'version "17(?:\.|")') {
|
||||
throw "需要 JDK 17,当前 java -version 输出: $javaVersion"
|
||||
}
|
||||
|
||||
$env:ANDROID_HOME = $sdkRoot
|
||||
$env:ANDROID_SDK_ROOT = $sdkRoot
|
||||
|
||||
Write-Host "==> 验证 Android 工程"
|
||||
Push-Location (Join-Path $PSScriptRoot "android-buyer")
|
||||
try {
|
||||
& $gradle test assembleDebug --no-daemon
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Android 构建失败,退出码: $LASTEXITCODE"
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Write-Host "==> Debug APK: $apk"
|
||||
|
||||
if ($env:RUN_START_COMMAND -eq "1") {
|
||||
Invoke-Expression $StartCmd
|
||||
if (-not (Test-Path -LiteralPath $adb)) {
|
||||
throw "缺少 SDK Platform Tools: $adb"
|
||||
}
|
||||
|
||||
$devices = & $adb devices
|
||||
if (($devices -join "`n") -notmatch "\sdevice\s*$") {
|
||||
throw "没有已授权的 Android 设备。"
|
||||
}
|
||||
|
||||
Write-Host "==> 安装并启动 Debug APK"
|
||||
& $adb install -r -t $apk
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "APK 安装失败,退出码: $LASTEXITCODE"
|
||||
}
|
||||
& $adb shell am start -W -n "com.roubao.autopilot/.MainActivity"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "App 启动失败,退出码: $LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user