-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild_aar.ps1
More file actions
54 lines (47 loc) · 1.82 KB
/
build_aar.ps1
File metadata and controls
54 lines (47 loc) · 1.82 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
# ==============================================================================
# MasterDnsVPN - Build gomobile .aar
# Usage: .\build_aar.ps1
# Requirements:
# - Android NDK r26+ somewhere on disk; set ANDROID_NDK_HOME if needed.
# - gomobile installed: go install golang.org/x/mobile/cmd/gomobile@latest
# gomobile init
# ==============================================================================
$ErrorActionPreference = "Stop"
$Root = $PSScriptRoot
$OutDir = "$Root\android\app\libs"
Write-Host "==> MasterDnsVPN - building gomobile .aar" -ForegroundColor Cyan
# Auto-detect Android NDK if ANDROID_NDK_HOME is not set
if (-not $env:ANDROID_NDK_HOME) {
$sdkRoot = $env:ANDROID_HOME
if (-not $sdkRoot) { $sdkRoot = "$env:USERPROFILE\AppData\Local\Android\Sdk" }
$ndkDir = "$sdkRoot\ndk"
if (Test-Path $ndkDir) {
$latest = Get-ChildItem $ndkDir | Sort-Object Name -Descending | Select-Object -First 1
if ($latest) {
$env:ANDROID_NDK_HOME = $latest.FullName.Trim()
Write-Host " NDK auto-detected: $env:ANDROID_NDK_HOME" -ForegroundColor DarkGray
}
}
}
# Ensure gomobile is on PATH
if (-not (Get-Command gomobile -ErrorAction SilentlyContinue)) {
Write-Host "gomobile not found. Installing..." -ForegroundColor Yellow
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
}
# Allow gomobile to download its bind package (not in vendor)
$env:GOFLAGS = "-mod=mod"
Push-Location $Root
try {
gomobile bind `
-v `
-target android `
-androidapi 26 `
-javapkg com.masterdnsvpn.gomobile `
-o "$OutDir\masterdnsvpn.aar" `
masterdnsvpn-go/cmd/android
Write-Host ""
Write-Host "==> Done! .aar written to: $OutDir\masterdnsvpn.aar" -ForegroundColor Green
} finally {
Pop-Location
}