101 lines
3.5 KiB
PowerShell
101 lines
3.5 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)][string]$Version
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$sdkRoot = (Resolve-Path (Join-Path $scriptDir "..\..\..")).Path
|
|
$androidRoot = Join-Path $sdkRoot "sdk\android"
|
|
$distDir = Join-Path $sdkRoot "sdk\dist"
|
|
$aarOutputDir = Join-Path $androidRoot "httpdns-sdk\build\outputs\aar"
|
|
$localMavenRoot = Join-Path $androidRoot "local-maven\com\newsdk\ams"
|
|
|
|
if (!(Test-Path $androidRoot)) {
|
|
throw "Android SDK directory not found: $androidRoot"
|
|
}
|
|
|
|
New-Item -ItemType Directory -Path $distDir -Force | Out-Null
|
|
|
|
Write-Host "Building Android SDK..."
|
|
Push-Location $androidRoot
|
|
try {
|
|
& .\gradlew.bat :httpdns-sdk:clean :httpdns-sdk:assembleNormalRelease
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
|
|
$aar = Get-ChildItem -Path $aarOutputDir -Filter ("new--android-httpdns-v{0}.aar" -f $Version) -File -ErrorAction SilentlyContinue |
|
|
Sort-Object LastWriteTime -Descending |
|
|
Select-Object -First 1
|
|
|
|
if ($null -eq $aar) {
|
|
$aar = Get-ChildItem -Path $aarOutputDir -Filter "new--android-httpdns-v*.aar" -File -ErrorAction SilentlyContinue |
|
|
Sort-Object LastWriteTime -Descending |
|
|
Select-Object -First 1
|
|
}
|
|
|
|
if ($null -eq $aar) {
|
|
$aar = Get-ChildItem -Path $aarOutputDir -Filter "*normal-release*.aar" -File -ErrorAction SilentlyContinue |
|
|
Sort-Object LastWriteTime -Descending |
|
|
Select-Object -First 1
|
|
}
|
|
|
|
if ($null -eq $aar) {
|
|
$aar = Get-ChildItem -Path $aarOutputDir -Filter "*release*.aar" -File -ErrorAction SilentlyContinue |
|
|
Sort-Object LastWriteTime -Descending |
|
|
Select-Object -First 1
|
|
}
|
|
|
|
if ($null -eq $aar) {
|
|
throw "AAR not found: $aarOutputDir"
|
|
}
|
|
|
|
$targetAarName = "new--android-httpdns-v$Version.aar"
|
|
$crashDefend = Join-Path $localMavenRoot "new-android-crashdefend\0.0.6\new-android-crashdefend-0.0.6.jar"
|
|
$ipDetector = Join-Path $localMavenRoot "new-android-ipdetector\1.2.0\new-android-ipdetector-1.2.0.aar"
|
|
$logger = Join-Path $localMavenRoot "new-android-logger\1.2.0\new-android-logger-1.2.0.aar"
|
|
|
|
foreach ($requiredFile in @($crashDefend, $ipDetector, $logger)) {
|
|
if (!(Test-Path $requiredFile)) {
|
|
throw "Required file missing: $requiredFile"
|
|
}
|
|
}
|
|
|
|
$stageDir = Join-Path $sdkRoot ("sdk\.tmp_android_release_{0}" -f [System.Guid]::NewGuid().ToString("N"))
|
|
New-Item -ItemType Directory -Path $stageDir -Force | Out-Null
|
|
|
|
try {
|
|
Copy-Item -Path $aar.FullName -Destination (Join-Path $stageDir $targetAarName) -Force
|
|
Copy-Item -Path $crashDefend -Destination (Join-Path $stageDir "new-android-crashdefend-0.0.6.jar") -Force
|
|
Copy-Item -Path $ipDetector -Destination (Join-Path $stageDir "new-android-ipdetector-1.2.0.aar") -Force
|
|
Copy-Item -Path $logger -Destination (Join-Path $stageDir "new-android-logger-1.2.0.aar") -Force
|
|
|
|
$zipWithVersion = Join-Path $distDir ("httpdns-sdk-android-v{0}.zip" -f $Version)
|
|
|
|
$zipNoVersion = Join-Path $distDir "httpdns-sdk-android.zip"
|
|
if (Test-Path $zipNoVersion) { Remove-Item -Path $zipNoVersion -Force }
|
|
if (Test-Path $zipWithVersion) { Remove-Item -Path $zipWithVersion -Force }
|
|
|
|
Compress-Archive -Path (Join-Path $stageDir "*") -DestinationPath $zipWithVersion -CompressionLevel Optimal
|
|
}
|
|
finally {
|
|
if (Test-Path $stageDir) {
|
|
Remove-Item -Path $stageDir -Recurse -Force
|
|
}
|
|
}
|
|
|
|
$standaloneAar = Join-Path $distDir $targetAarName
|
|
if (Test-Path $standaloneAar) {
|
|
Remove-Item -Path $standaloneAar -Force
|
|
}
|
|
|
|
$outputsDir = Join-Path $androidRoot "httpdns-sdk\build\outputs"
|
|
if (Test-Path $outputsDir) {
|
|
Remove-Item -Path $outputsDir -Recurse -Force
|
|
}
|
|
|
|
Write-Host "Android SDK build complete (zip only)."
|
|
Write-Host "ZIP: $zipWithVersion"
|