-
Notifications
You must be signed in to change notification settings - Fork 532
/
install-android-ndk.ps1
52 lines (40 loc) · 1.32 KB
/
install-android-ndk.ps1
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
Param(
[string] $Version = "r21",
[string] $InstallDestination = $null
)
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName System.IO.Compression.FileSystem
$HOME_DIR = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }
if ($IsMacOS) {
$platform = "darwin-x86_64"
} elseif ($IsLinux) {
$platform = "linux-x86_64"
} else {
$platform = "windows-x86_64"
}
$url = "https://dl.google.com/android/repository/android-ndk-${Version}-${platform}.zip"
$ndk = "$HOME_DIR/android-ndk"
if ($InstallDestination) {
$ndk = $InstallDestination
}
Write-Host "Install destination is '$ndk'..."
$ndkTemp = "$HOME_DIR/android-ndk-temp"
$install = "$ndkTemp/android-ndk.zip"
# download
Write-Host "Downloading NDK..."
New-Item -ItemType Directory -Force -Path "$ndkTemp" | Out-Null
(New-Object System.Net.WebClient).DownloadFile("$url", "$install")
# extract
Write-Host "Extracting NDK..."
if ($IsMacOS -or $IsLinux) {
# use the native command to preserve permissions
unzip "$install" -d "$ndkTemp"
}else {
[System.IO.Compression.ZipFile]::ExtractToDirectory("$install", "$ndkTemp")
}
# move / rename
Write-Host "Moving NDK..."
Move-Item "${ndkTemp}\android-ndk-${Version}" "$ndk"
# make sure that NDK is in ANDROID_NDK_HOME
Write-Host "##vso[task.setvariable variable=ANDROID_NDK_HOME;]$ndk";
exit $LASTEXITCODE