Files
SimpleWriting/scripts/install_android_build.ps1
2026-07-10 17:09:39 +08:00

46 lines
2.0 KiB
PowerShell

# Android APK 构建环境一键安装脚本
# 右键此文件 → 使用 PowerShell 运行,或在终端输入:powershell -File install_android_build.ps1
$ErrorActionPreference = "Stop"
$JDK_HOME = "C:\Program Files\Eclipse Adoptium\jdk-17.0.17.10-hotspot"
$ANDROID_HOME = "C:\Android"
Write-Host "===== 1/3: 刷新环境变量 =====" -ForegroundColor Green
$env:JAVA_HOME = $JDK_HOME
$env:ANDROID_HOME = $ANDROID_HOME
$env:PATH = "$JDK_HOME\bin;$ANDROID_HOME\cmdline-tools\latest\bin;$env:PATH"
java -version
Write-Host "===== 2/3: 安装 Android SDK 组件 =====" -ForegroundColor Green
# 接受 SDK 许可
cmd /c "yes | `"$ANDROID_HOME\cmdline-tools\latest\bin\sdkmanager.bat`" --sdk_root=$ANDROID_HOME --licenses" 2>$null
# 安装必要的 SDK 组件
cmd /c "`"$ANDROID_HOME\cmdline-tools\latest\bin\sdkmanager.bat`" --sdk_root=$ANDROID_HOME platform-tools platforms;android-35 build-tools;35.0.0"
Write-Host "===== 3/3: 构建 APK =====" -ForegroundColor Green
$projectDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location "$projectDir\..\android"
$env:JAVA_HOME = $JDK_HOME
$env:ANDROID_HOME = $ANDROID_HOME
$env:PATH = "$JDK_HOME\bin;$ANDROID_HOME\cmdline-tools\latest\bin;$env:PATH"
cmd /c "set JAVA_HOME=$JDK_HOME&& set ANDROID_HOME=$ANDROID_HOME&& set PATH=%JAVA_HOME%\bin;%ANDROID_HOME%\cmdline-tools\latest\bin;%PATH%&& gradlew assembleDebug"
$apkPath = "$projectDir\..\android\app\build\outputs\apk\debug\app-debug.apk"
if (Test-Path $apkPath) {
Write-Host "===== APK 构建成功! =====" -ForegroundColor Green
Write-Host "APK 位置: $apkPath" -ForegroundColor Yellow
Write-Host "大小: $((Get-Item $apkPath).Length / 1MB) MB" -ForegroundColor Yellow
# 复制到桌面方便找
Copy-Item $apkPath "$env:USERPROFILE\Desktop\bote.apk" -Force
Write-Host "已复制到桌面: bote.apk" -ForegroundColor Yellow
} else {
Write-Host "构建失败,请检查上面的错误信息" -ForegroundColor Red
}
Write-Host "按任意键退出..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")