-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbuild-android.ps1
More file actions
96 lines (78 loc) · 2.89 KB
/
build-android.ps1
File metadata and controls
96 lines (78 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
$ErrorActionPreference = 'Stop'
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
function Get-FlutterCommand {
if ($env:FLUTTER_BIN -and (Test-Path $env:FLUTTER_BIN)) {
return $env:FLUTTER_BIN
}
$candidate = "C:\flutter\bin\flutter.bat"
if (Test-Path $candidate) { return $candidate }
$flutterCmd = Get-Command flutter -ErrorAction SilentlyContinue
if ($flutterCmd) { return $flutterCmd.Source }
throw "Flutter not found. Install Flutter, add it to PATH, or set FLUTTER_BIN to the full flutter executable path."
}
function Get-AppVersion {
$pubspecPath = Join-Path $repoRoot "pubspec.yaml"
if (-not (Test-Path $pubspecPath)) {
throw "pubspec.yaml not found at $pubspecPath"
}
$versionLine = Get-Content $pubspecPath | Where-Object { $_ -match '^version\s*:\s*' } | Select-Object -First 1
if (-not $versionLine) {
throw "Could not find version in pubspec.yaml"
}
$fullVersion = ($versionLine -split ':', 2)[1].Trim()
$appVersion = ($fullVersion -split '\+', 2)[0].Trim()
if ([string]::IsNullOrWhiteSpace($appVersion)) {
throw "Invalid version value in pubspec.yaml: $fullVersion"
}
return $appVersion
}
$flutterExe = Get-FlutterCommand
$appVersion = Get-AppVersion
$apkSource = Join-Path $repoRoot "build\app\outputs\flutter-apk\app-release.apk"
$apkOutput = Join-Path $repoRoot "Moonfin_Android_v$appVersion.apk"
$checkerScript = Join-Path $repoRoot "scripts\check-android-16kb-pages.sh"
Push-Location $repoRoot
try {
Write-Host "Moonfin version: $appVersion"
Write-Host "Cleaning previous Flutter outputs..."
& $flutterExe clean
if ($LASTEXITCODE -ne 0) {
throw "flutter clean failed with exit code $LASTEXITCODE"
}
Write-Host "Resolving Dart and Flutter packages..."
& $flutterExe pub get
if ($LASTEXITCODE -ne 0) {
throw "flutter pub get failed with exit code $LASTEXITCODE"
}
Write-Host "Building Android release APK (arm64-v8a only)..."
& $flutterExe build apk --release --target-platform android-arm64
if ($LASTEXITCODE -ne 0) {
throw "flutter build apk failed with exit code $LASTEXITCODE"
}
if (-not (Test-Path $apkSource)) {
throw "APK not found at expected path: $apkSource"
}
Copy-Item -Path $apkSource -Destination $apkOutput -Force
if (Test-Path $checkerScript) {
$bashCmd = Get-Command bash -ErrorAction SilentlyContinue
if ($bashCmd) {
Write-Host "Running 16 KB page-size compatibility check on APK..."
& $bashCmd.Source $checkerScript $apkSource
if ($LASTEXITCODE -ne 0) {
throw "16 KB page-size compatibility check failed with exit code $LASTEXITCODE"
}
}
else {
Write-Warning "bash not found; skipping 16 KB page-size compatibility check"
}
}
else {
Write-Warning "16 KB checker script not found at $checkerScript"
}
Write-Host ""
Write-Host "APK created:" $apkSource
Write-Host "APK copied to root:" $apkOutput
}
finally {
Pop-Location
}