2019-02-09 21:23:09 +03:00
|
|
|
Param(
|
2023-08-14 23:17:49 +03:00
|
|
|
[string] $Version = "r25c",
|
2019-07-26 16:05:54 +03:00
|
|
|
[string] $InstallDestination = $null
|
2019-02-09 21:23:09 +03:00
|
|
|
)
|
2019-02-05 06:22:35 +03:00
|
|
|
|
2019-05-24 08:14:37 +03:00
|
|
|
$ErrorActionPreference = 'Stop'
|
2020-07-07 20:15:40 +03:00
|
|
|
|
2019-02-05 06:22:35 +03:00
|
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
|
|
|
2020-07-07 20:15:40 +03:00
|
|
|
$HOME_DIR = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }
|
|
|
|
|
2019-02-09 21:23:09 +03:00
|
|
|
if ($IsMacOS) {
|
2023-08-14 23:17:49 +03:00
|
|
|
$platform = "darwin.dmg"
|
2019-02-09 21:23:09 +03:00
|
|
|
} elseif ($IsLinux) {
|
2023-08-14 23:17:49 +03:00
|
|
|
$platform = "linux.zip"
|
2019-02-09 21:23:09 +03:00
|
|
|
} else {
|
2023-08-14 23:17:49 +03:00
|
|
|
$platform = "windows.zip"
|
2019-02-09 21:23:09 +03:00
|
|
|
}
|
|
|
|
|
2023-08-14 23:17:49 +03:00
|
|
|
$url = "https://dl.google.com/android/repository/android-ndk-${Version}-${platform}"
|
2019-07-26 16:05:54 +03:00
|
|
|
|
2020-07-07 20:15:40 +03:00
|
|
|
$ndk = "$HOME_DIR/android-ndk"
|
2019-07-26 16:05:54 +03:00
|
|
|
if ($InstallDestination) {
|
|
|
|
$ndk = $InstallDestination
|
|
|
|
}
|
2023-08-14 23:17:49 +03:00
|
|
|
Write-Host "Install destination is '$ndk'."
|
2019-07-26 16:05:54 +03:00
|
|
|
|
2020-07-07 20:15:40 +03:00
|
|
|
$ndkTemp = "$HOME_DIR/android-ndk-temp"
|
2023-08-14 23:17:49 +03:00
|
|
|
$install = "$ndkTemp/android-ndk-${platform}"
|
2019-02-09 21:23:09 +03:00
|
|
|
|
|
|
|
# download
|
2024-07-29 15:48:02 +03:00
|
|
|
Write-Host "Downloading NDK ($url) to '$install'..."
|
2019-02-09 21:23:09 +03:00
|
|
|
New-Item -ItemType Directory -Force -Path "$ndkTemp" | Out-Null
|
|
|
|
(New-Object System.Net.WebClient).DownloadFile("$url", "$install")
|
2019-02-05 06:22:35 +03:00
|
|
|
|
2019-02-09 21:23:09 +03:00
|
|
|
# extract
|
|
|
|
Write-Host "Extracting NDK..."
|
2023-08-14 23:17:49 +03:00
|
|
|
if ($IsMacOS) {
|
2024-01-08 22:06:21 +03:00
|
|
|
hdiutil attach $install -verbose
|
2023-08-14 23:17:49 +03:00
|
|
|
$ndkSource = (Get-ChildItem "/Volumes/Android NDK ${Version}/AndroidNDK*.app/Contents/NDK").Fullname
|
2024-01-08 22:06:21 +03:00
|
|
|
Write-Host "Copying NDK..."
|
2023-08-14 23:17:49 +03:00
|
|
|
New-Item -ItemType Directory -Force -Path "$ndk" | Out-Null
|
|
|
|
cp -r "$ndkSource/" "$ndk"
|
|
|
|
hdiutil detach "/Volumes/Android NDK ${Version}"
|
|
|
|
} elseif ($IsLinux) {
|
2019-02-09 21:23:09 +03:00
|
|
|
unzip "$install" -d "$ndkTemp"
|
2023-08-14 23:17:49 +03:00
|
|
|
Write-Host "Moving NDK..."
|
|
|
|
Move-Item "${ndkTemp}\android-ndk-${Version}" "$ndk"
|
|
|
|
} else {
|
2019-02-09 21:23:09 +03:00
|
|
|
[System.IO.Compression.ZipFile]::ExtractToDirectory("$install", "$ndkTemp")
|
2023-08-14 23:17:49 +03:00
|
|
|
Write-Host "Moving NDK..."
|
|
|
|
Move-Item "${ndkTemp}\android-ndk-${Version}" "$ndk"
|
2019-02-09 21:23:09 +03:00
|
|
|
}
|
2019-02-05 06:22:35 +03:00
|
|
|
|
2019-06-25 10:10:09 +03:00
|
|
|
# make sure that NDK is in ANDROID_NDK_HOME
|
|
|
|
Write-Host "##vso[task.setvariable variable=ANDROID_NDK_HOME;]$ndk";
|
|
|
|
|
2019-02-05 06:22:35 +03:00
|
|
|
exit $LASTEXITCODE
|