-
Notifications
You must be signed in to change notification settings - Fork 570
/
Copy pathinstall-android-ndk.ps1
58 lines (47 loc) · 1.68 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
53
54
55
56
57
58
Param(
[string] $Version = "r27c",
[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.dmg"
} elseif ($IsLinux) {
$platform = "linux.zip"
} else {
$platform = "windows.zip"
}
$url = "https://dl.google.com/android/repository/android-ndk-${Version}-${platform}"
$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-${platform}"
# download
Write-Host "Downloading NDK ($url) to '$install'..."
New-Item -ItemType Directory -Force -Path "$ndkTemp" | Out-Null
(New-Object System.Net.WebClient).DownloadFile("$url", "$install")
# extract
Write-Host "Extracting NDK..."
if ($IsMacOS) {
hdiutil attach $install -verbose
$ndkSource = (Get-ChildItem "/Volumes/Android NDK ${Version}/AndroidNDK*.app/Contents/NDK").Fullname
Write-Host "Copying NDK..."
New-Item -ItemType Directory -Force -Path "$ndk" | Out-Null
cp -r "$ndkSource/" "$ndk"
hdiutil detach "/Volumes/Android NDK ${Version}"
} elseif ($IsLinux) {
unzip "$install" -d "$ndkTemp"
Write-Host "Moving NDK..."
Move-Item "${ndkTemp}\android-ndk-${Version}" "$ndk"
} else {
[System.IO.Compression.ZipFile]::ExtractToDirectory("$install", "$ndkTemp")
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