param([string]$ApiUrl = 'https://wms.svc.cmvr-iot.icu/prod-api', [string]$UpdateOrigin = 'https://wms.svc.cmvr-iot.icu') $ErrorActionPreference = 'Stop' $taskApp = Split-Path $PSScriptRoot -Parent $taskRepo = Split-Path $taskApp -Parent $taskSigning = Join-Path $taskApp 'keys/production' try { $taskSecret = (Get-Content -LiteralPath (Join-Path $taskSigning 'credentials.dpapi') -Raw).Trim() | ConvertTo-SecureString $taskPtr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($taskSecret) try { $taskCredentials = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($taskPtr) | ConvertFrom-Json } finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($taskPtr) } } catch { $taskProtected = [IO.File]::ReadAllBytes((Join-Path $taskSigning 'credentials.machine.dpapi')) $taskUnprotected = [System.Security.Cryptography.ProtectedData]::Unprotect($taskProtected, $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine) $taskCredentials = [Text.Encoding]::UTF8.GetString($taskUnprotected) | ConvertFrom-Json [Array]::Clear($taskUnprotected, 0, $taskUnprotected.Length) } try { $env:APP_API_URL = $ApiUrl $env:APP_UPDATE_ORIGIN = $UpdateOrigin $env:CMVR_KEYSTORE = Join-Path $taskSigning 'cmvr-production.p12' $env:CMVR_STORE_PASSWORD = $taskCredentials.storePassword $env:CMVR_KEY_PASSWORD = $taskCredentials.storePassword $env:CMVR_KEY_ALIAS = $taskCredentials.alias & (Join-Path $PSScriptRoot 'Build-Android.ps1') -Environment prod -GradlePath (Join-Path $taskRepo '.codex-tmp/expo-tools/gradle-9.4.1/bin/gradle.bat') } finally { foreach ($taskName in @('CMVR_KEYSTORE','CMVR_STORE_PASSWORD','CMVR_KEY_PASSWORD','CMVR_KEY_ALIAS')) { Remove-Item -LiteralPath "Env:$taskName" -ErrorAction SilentlyContinue } $taskCredentials = $null }