/
DemienMedich
/
BodyweightBase
Обзор
Документация
Войти
/
DemienMedich
/
BodyweightBase
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
build-android.ps1
128 строк
5 KB
DemienMedich
Harden package verification and clean startup
18 июл 2026, 21:15
18 июл 2026, 21:15
35f16e9
Код
Авторство
О чём код?
param( [string]$PythonCommand = "python", [switch]$KeepStaging ) $ErrorActionPreference = "Stop" $qtRoot = "Z:\Soft\Qt\6.7.3" $qtAndroid = Join-Path $qtRoot "android_arm64_v8a" $qtHost = Join-Path $qtRoot "mingw_64" $androidSdk = "Z:\Android\Sdk" $androidNdk = Join-Path $androidSdk "ndk\27.2.12479018" $buildDir = Join-Path $PSScriptRoot "build-android" $appBuildDir = Join-Path $buildDir "app" $assetAudit = Join-Path $PSScriptRoot "tools\audit_exercise_frames.py" function Remove-AndroidStaging([string]$Path) { if (-not (Test-Path -LiteralPath $Path)) { return } $fullPath = [System.IO.Path]::GetFullPath($Path) $allowedRoot = [System.IO.Path]::GetFullPath($appBuildDir).TrimEnd('\') + '\' $leaf = Split-Path $fullPath -Leaf if (-not $fullPath.StartsWith($allowedRoot, [System.StringComparison]::OrdinalIgnoreCase) -or $leaf -notlike 'android-build-work-*') { throw "Refusing to remove unexpected Android staging path: $fullPath" } $wrapper = Join-Path $fullPath "gradlew.bat" if (Test-Path -LiteralPath $wrapper) { & $wrapper --stop 2>$null | Out-Null } for ($attempt = 1; $attempt -le 3; ++$attempt) { try { Remove-Item -LiteralPath $fullPath -Recurse -Force -ErrorAction Stop return } catch { if ($attempt -eq 3) { Write-Warning "Could not remove Android staging directory: $fullPath ($($_.Exception.Message))" return } Start-Sleep -Milliseconds 500 } } } if (-not (Test-Path (Join-Path $qtAndroid "lib\cmake\Qt6\qt.toolchain.cmake"))) { throw "Qt for Android not found: $qtAndroid" } if (-not (Test-Path $androidNdk)) { throw "Android NDK not found: $androidNdk" } & $PythonCommand -B $assetAudit if ($LASTEXITCODE -ne 0) { throw "Exercise frame audit failed with exit code $LASTEXITCODE" } if (-not $KeepStaging -and (Test-Path -LiteralPath $appBuildDir)) { Get-ChildItem -LiteralPath $appBuildDir -Directory -Filter 'android-build-work-*' -ErrorAction SilentlyContinue | ForEach-Object { Remove-AndroidStaging $_.FullName } } $env:ANDROID_HOME = $androidSdk $env:ANDROID_SDK_ROOT = $androidSdk $env:ANDROID_NDK_ROOT = $androidNdk $hostToolPaths = @((Join-Path $qtHost "bin")) $gitMinGwRuntime = "Z:\Soft\Git\mingw64\bin" if (Test-Path (Join-Path $gitMinGwRuntime "libstdc++-6.dll")) { $hostToolPaths += $gitMinGwRuntime } $env:Path = (($hostToolPaths + $env:Path) -join ";") cmake -S $PSScriptRoot -B $buildDir -G Ninja ` -DCMAKE_BUILD_TYPE=Release ` -DCMAKE_TOOLCHAIN_FILE="$qtAndroid\lib\cmake\Qt6\qt.toolchain.cmake" ` -DQT_HOST_PATH="$qtHost" ` -DANDROID_SDK_ROOT="$androidSdk" ` -DANDROID_NDK_ROOT="$androidNdk" ` -DANDROID_ABI=arm64-v8a ` -DQT_ANDROID_BUILD_ALL_ABIS=OFF cmake --build $buildDir --target BodyweightBaseCppApp --parallel 4 if ($LASTEXITCODE -ne 0) { throw "Android native build failed with exit code $LASTEXITCODE" } $androidBuildDir = Join-Path $appBuildDir "android-build-work-$PID" $deploymentSettings = Join-Path $appBuildDir "android-BodyweightBaseCppApp-deployment-settings.json" $nativeLib = Join-Path $appBuildDir "libBodyweightBaseCppApp_arm64-v8a.so" $apkOutput = Join-Path $androidBuildDir "BodyweightBaseCppApp.apk" $gradleApkOutput = Join-Path $androidBuildDir "build\outputs\apk\debug\android-build-debug.apk" $abiLibDir = Join-Path $androidBuildDir "libs\arm64-v8a" $gradleWrapper = Join-Path $androidBuildDir "gradlew.bat" if (Test-Path $gradleWrapper) { & $gradleWrapper --stop | Out-Null } New-Item -ItemType Directory -Force -Path $abiLibDir | Out-Null Copy-Item -LiteralPath $nativeLib -Destination $abiLibDir -Force Remove-Item -LiteralPath $apkOutput -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $gradleApkOutput -Force -ErrorAction SilentlyContinue & (Join-Path $qtHost "bin\androiddeployqt.exe") ` --input $deploymentSettings ` --output $androidBuildDir ` --android-platform android-34 ` --apk $apkOutput if ($LASTEXITCODE -ne 0) { throw "androiddeployqt failed with exit code $LASTEXITCODE" } $apk = Get-Item -LiteralPath $apkOutput -ErrorAction SilentlyContinue if (-not $apk) { throw "Android APK was not produced" } $destination = Join-Path $PSScriptRoot "dist\Android\BodyweightBaseQt-arm64.apk" New-Item -ItemType Directory -Force -Path (Split-Path $destination) | Out-Null Copy-Item -LiteralPath $apk.FullName -Destination $destination -Force $destinationHash = "$destination.sha256" $hash = (Get-FileHash $destination -Algorithm SHA256).Hash Set-Content -LiteralPath $destinationHash -Value "$hash $(Split-Path $destination -Leaf)" -Encoding ASCII Write-Host "APK: $destination" Write-Host "SizeMB: $([math]::Round((Get-Item -LiteralPath $destination).Length / 1MB, 2))" Write-Host "SHA256: $hash" if (-not $KeepStaging) { Remove-AndroidStaging $androidBuildDir }