cmvr-wms/mobile-app/scripts/Build-Android.ps1
lixiaolong 149bde836f feat(assistant): 扩展业务助手功能支持更多文档类型和业务场景
- 新增 PDF 文档支持,包括格式校验和完整性检查
- 扩展 Word、TXT 和 ZIP 格式附件处理能力
- 添加 Excel 附件可选择仅作为业务文件不解析行数据
- 实现业务助手表格布局配置新增库存和预算字段
- 集成通知、反馈通知等新的业务助手动作类型
- 完善部门管理包含父级部门和排序字段支持
- 增强业务规则校验涵盖更多系统管理场景
- 优化附件上传限制提示信息更准确
- 添加生成文件下载的安全性校验机制
- 扩展测试覆盖确保各业务动作规则正确性
2026-10-18 08:49:30 +08:00

64 lines
4.0 KiB
PowerShell

param(
[ValidateSet('dev','prod')][string]$Environment = 'dev',
[string]$GradlePath = '',
[string]$Architectures = 'arm64-v8a'
)
$ErrorActionPreference = 'Stop'
$taskApp = Split-Path $PSScriptRoot -Parent
$taskRepo = Split-Path $taskApp -Parent
if (!(Test-Path -LiteralPath (Join-Path $taskApp 'app.config.js'))) { throw 'Expo App root not found' }
if (!$env:JAVA_HOME -or !$env:ANDROID_HOME) { throw 'Set JAVA_HOME (Java 17+) and ANDROID_HOME first.' }
if ($Environment -eq 'prod') {
foreach ($name in @('APP_API_URL','APP_UPDATE_ORIGIN','CMVR_KEYSTORE','CMVR_STORE_PASSWORD','CMVR_KEY_ALIAS','CMVR_KEY_PASSWORD')) {
if (![Environment]::GetEnvironmentVariable($name)) { throw "Missing production environment variable: $name" }
}
if (!(Test-Path -LiteralPath (Join-Path $taskApp 'certs/prod.pem'))) { throw 'Configure the production OTA public certificate first. Never use the development key.' }
}
$env:APP_ENV = $Environment
$env:EXPO_NO_TELEMETRY = '1'
$taskTmp = Join-Path $taskRepo '.codex-tmp/jtmp'
New-Item -ItemType Directory -Path $taskTmp -Force | Out-Null
$env:JAVA_TOOL_OPTIONS = "$env:JAVA_TOOL_OPTIONS -Dfile.encoding=UTF-8 -Djava.io.tmpdir=$taskTmp -Djdk.net.unixdomain.tmpdir=$taskTmp"
Push-Location $taskApp
try {
& npm.cmd run typecheck
if ($LASTEXITCODE) { throw 'Type checking failed' }
& npm.cmd test
if ($LASTEXITCODE) { throw 'Regression tests failed' }
# Do not carry a signing configuration or application ID across environments.
$taskGenerated = Join-Path $taskApp 'android'
$taskGeneratedGradle = Join-Path $taskGenerated 'app/build.gradle'
$taskExpectedPackage = if ($Environment -eq 'prod') { 'cn.cmvr.wms' } else { 'cn.cmvr.wms.dev' }
if (Test-Path -LiteralPath $taskGeneratedGradle) {
$taskGradleSource = Get-Content -LiteralPath $taskGeneratedGradle -Raw
if ($taskGradleSource -notmatch ('applicationId\s+["'']' + [regex]::Escape($taskExpectedPackage) + '["'']')) {
$taskResolvedGenerated = (Resolve-Path -LiteralPath $taskGenerated).Path
if ($taskResolvedGenerated -ne (Join-Path (Resolve-Path -LiteralPath $taskApp).Path 'android')) { throw 'Unexpected generated Android directory' }
Move-Item -LiteralPath $taskResolvedGenerated -Destination (Join-Path $taskRepo ('.codex-tmp/expo-android-' + [Guid]::NewGuid().ToString('N')))
}
}
# This is Expo's generated directory in mobile-app, never the existing android-app.
& npx.cmd expo prebuild --platform android --no-install
if ($LASTEXITCODE) { throw 'Native configuration generation failed' }
# Ninja 1.10 can build fresh objects but cannot reopen its absolute-header
# dependency cache under this long Windows checkout. Preserve only our own
# generated native cache and reconfigure; never change machine security settings.
if ([Environment]::OSVersion.Platform -eq [PlatformID]::Win32NT) {
$taskNativeCache = Join-Path $taskApp 'android/app/.cxx'
if (Test-Path -LiteralPath $taskNativeCache) {
$taskResolvedCache = (Resolve-Path -LiteralPath $taskNativeCache).Path
$taskAllowedApp = (Resolve-Path -LiteralPath (Join-Path $taskApp 'android/app')).Path
if ($taskResolvedCache -ne (Join-Path $taskAllowedApp '.cxx')) { throw 'Unexpected native cache path' }
$taskCacheBackup = Join-Path $taskRepo ('.codex-tmp/expo-cxx-' + [Guid]::NewGuid().ToString('N'))
Move-Item -LiteralPath $taskResolvedCache -Destination $taskCacheBackup
}
}
Push-Location (Join-Path $taskApp 'android')
try {
if ($GradlePath) { & $GradlePath ':app:assembleRelease' '--no-daemon' "-PreactNativeArchitectures=$Architectures" }
else { & ./gradlew.bat ':app:assembleRelease' '--no-daemon' "-PreactNativeArchitectures=$Architectures" }
if ($LASTEXITCODE) { throw 'Android build failed' }
} finally { Pop-Location }
Write-Output (Join-Path $taskApp 'android/app/build/outputs/apk/release/app-release.apk')
} finally { Pop-Location }