61 lines
3.0 KiB
PowerShell
61 lines
3.0 KiB
PowerShell
param([switch]$ShowSigningPassword)
|
|||
|
|
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
$projectRoot = Split-Path -Parent $PSScriptRoot
|
||
|
|
$androidSdk = Join-Path $env:LOCALAPPDATA 'Android\Sdk'
|
||
|
|
$javaHome = 'C:\Program Files\Android\Android Studio\jbr'
|
||
|
|
$keytool = Join-Path $javaHome 'bin\keytool.exe'
|
||
|
|
$signingDir = Join-Path $env:USERPROFILE '.android'
|
||
|
|
$storePath = Join-Path $signingDir 'litellm-dashboard-upload.jks'
|
||
|
|
$secretPath = Join-Path $signingDir 'litellm-dashboard-upload.password.dpapi'
|
||
|
|
$alias = 'litellm-dashboard-upload'
|
||
|
|
|
||
|
|
if (-not (Test-Path -LiteralPath $keytool)) { throw "Android Studio JDK not found at $javaHome" }
|
||
|
|
if (-not (Test-Path -LiteralPath $androidSdk)) { throw "Android SDK not found at $androidSdk" }
|
||
|
|
New-Item -ItemType Directory -Path $signingDir -Force | Out-Null
|
||
|
|
|
||
|
|
$hasStore = Test-Path -LiteralPath $storePath
|
||
|
|
$hasSecret = Test-Path -LiteralPath $secretPath
|
||
|
|
if ($hasStore -xor $hasSecret) {
|
||
|
|
throw 'Only one signing file exists. Restore the missing keystore or password file before building; do not generate a replacement key for an existing app.'
|
||
|
|
}
|
||
|
|
|
||
|
|
if (-not $hasStore) {
|
||
|
|
$random = [System.Security.Cryptography.RandomNumberGenerator]::GetBytes(36)
|
||
|
|
$password = [Convert]::ToBase64String($random).TrimEnd('=').Replace('+', '-').Replace('/', '_')
|
||
|
|
& $keytool -genkeypair -keystore $storePath -storetype PKCS12 -alias $alias -keyalg RSA -keysize 3072 -validity 10000 -storepass $password -keypass $password -dname 'CN=LiteLLM Dashboard'
|
||
|
|
if ($LASTEXITCODE -ne 0) { throw 'Key generation failed.' }
|
||
|
|
$password | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Set-Content -LiteralPath $secretPath -NoNewline
|
||
|
|
Write-Host "Created local release key at $storePath"
|
||
|
|
}
|
||
|
|
|
||
|
|
$securePassword = Get-Content -LiteralPath $secretPath -Raw | ConvertTo-SecureString
|
||
|
|
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePassword)
|
||
|
|
try { $password = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer) }
|
||
|
|
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer) }
|
||
|
|
|
||
|
|
if ($ShowSigningPassword) {
|
||
|
|
Write-Host 'Signing password (back up securely, then clear your terminal):'
|
||
|
|
Write-Output $password
|
||
|
|
exit 0
|
||
|
|
}
|
||
|
|
|
||
|
|
$env:JAVA_HOME = $javaHome
|
||
|
|
$env:ANDROID_HOME = $androidSdk
|
||
|
|
$env:LITELLM_RELEASE_STORE_FILE = $storePath
|
||
|
|
$env:LITELLM_RELEASE_STORE_PASSWORD = $password
|
||
|
|
$env:LITELLM_RELEASE_KEY_ALIAS = $alias
|
||
|
|
$env:LITELLM_RELEASE_KEY_PASSWORD = $password
|
||
|
|
try {
|
||
|
|
Push-Location $projectRoot
|
||
|
|
try {
|
||
|
|
& .\gradlew.bat :app:assembleRelease :app:bundleRelease --no-daemon
|
||
|
|
if ($LASTEXITCODE -ne 0) { throw "Release build failed with exit code $LASTEXITCODE" }
|
||
|
|
} finally { Pop-Location }
|
||
|
|
} finally {
|
||
|
|
Remove-Item Env:LITELLM_RELEASE_STORE_FILE,Env:LITELLM_RELEASE_STORE_PASSWORD,Env:LITELLM_RELEASE_KEY_ALIAS,Env:LITELLM_RELEASE_KEY_PASSWORD -ErrorAction SilentlyContinue
|
||
|
|
$password = $null
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-Host 'Signed release APK: app\build\outputs\apk\release\app-release.apk'
|
||
|
|
Write-Host 'Signed release AAB: app\build\outputs\bundle\release\app-release.aab'
|