#!/usr/bin/env pwsh # ============================================ # 继续完成 APK 构建 # 使用场景:之前中断了构建,现在继续完成 # ============================================ $ErrorActionPreference = "Stop" Write-Host "========================================" -ForegroundColor Cyan Write-Host " 继续构建 APK" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" $SDKRoot = "D:\4_Part\HBuilder-Android\HBuilder-Integrate-AS" # 检查 SDK 目录 if (-Not (Test-Path $SDKRoot)) { Write-Host "错误:找不到 Android SDK 目录" -ForegroundColor Red Write-Host " 期望位置: $SDKRoot" -ForegroundColor Gray exit 1 } Write-Host "Android SDK 目录: $SDKRoot" -ForegroundColor Green Write-Host "" # 询问是否清理缓存 Write-Host "是否清理之前的构建缓存?" -ForegroundColor Yellow Write-Host " Y = 清理缓存重新构建(推荐,更干净)" -ForegroundColor Gray Write-Host " N = 继续之前的构建(更快,但可能有问题)" -ForegroundColor Gray $CleanCache = Read-Host "请选择 (Y/n)" Push-Location $SDKRoot try { if ($CleanCache -ne 'n' -and $CleanCache -ne 'N') { Write-Host "" Write-Host "正在清理缓存..." -ForegroundColor Yellow .\gradlew clean Write-Host " ✓ 缓存已清理" -ForegroundColor Green } Write-Host "" Write-Host "========================================" -ForegroundColor Yellow Write-Host " 开始构建 APK" -ForegroundColor Yellow Write-Host "========================================" -ForegroundColor Yellow Write-Host "" Write-Host "预计时间:" -ForegroundColor Cyan Write-Host " - 首次构建: 10-15 分钟" -ForegroundColor Gray Write-Host " - 继续构建: 5-8 分钟" -ForegroundColor Gray Write-Host "" Write-Host "开始构建..." -ForegroundColor Yellow Write-Host "" # 开始构建 .\gradlew assembleDebug if ($LASTEXITCODE -eq 0) { Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host " 构建成功!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "" # 查找 APK $APKPath = "$SDKRoot\simpleDemo\build\outputs\apk\debug\simpleDemo-debug.apk" if (Test-Path $APKPath) { $APKInfo = Get-Item $APKPath $SizeMB = [math]::Round($APKInfo.Length / 1MB, 2) Write-Host "APK 信息:" -ForegroundColor Cyan Write-Host " 位置: $APKPath" -ForegroundColor White Write-Host " 大小: $SizeMB MB" -ForegroundColor White Write-Host " 时间: $($APKInfo.LastWriteTime)" -ForegroundColor White Write-Host "" # 询问是否打开文件夹 $OpenFolder = Read-Host "是否打开 APK 所在文件夹? (Y/n)" if ($OpenFolder -ne 'n' -and $OpenFolder -ne 'N') { explorer.exe "/select,$APKPath" } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host " 下一步操作" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "1. 安装 APK 到手机进行测试" -ForegroundColor Yellow Write-Host "2. 测试所有功能:" -ForegroundColor Yellow Write-Host " ✓ 服务器连接 (192.168.1.8:30091)" -ForegroundColor Gray Write-Host " ✓ 学习记录" -ForegroundColor Gray Write-Host " ✓ 考试功能" -ForegroundColor Gray Write-Host " ✓ 课件查看" -ForegroundColor Gray Write-Host " ✓ 语音测评" -ForegroundColor Gray Write-Host "" Write-Host "3. 如需修改服务器地址:" -ForegroundColor Yellow Write-Host " 双击: 修改服务器地址.ps1" -ForegroundColor Gray Write-Host "" } else { Write-Host "警告:APK 文件未找到" -ForegroundColor Yellow Write-Host " 期望位置: $APKPath" -ForegroundColor Gray } } else { Write-Host "" Write-Host "构建失败,退出码: $LASTEXITCODE" -ForegroundColor Red Write-Host "" Write-Host "常见问题解决:" -ForegroundColor Yellow Write-Host " 1. 清理缓存后重试: .\gradlew clean" -ForegroundColor Gray Write-Host " 2. 检查网络连接" -ForegroundColor Gray Write-Host " 3. 确保有足够的磁盘空间" -ForegroundColor Gray Write-Host "" } } catch { Write-Host "" Write-Host "构建出错: $_" -ForegroundColor Red exit 1 } finally { Pop-Location } Write-Host "" Write-Host "按任意键退出..." $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")