67 lines
2.0 KiB
PowerShell
67 lines
2.0 KiB
PowerShell
[CmdletBinding()]
|
|
param()
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Get-AndroidSdkRoot {
|
|
$candidates = @(
|
|
$env:ANDROID_SDK_ROOT,
|
|
$env:ANDROID_HOME,
|
|
(Join-Path $env:LOCALAPPDATA "Android\Sdk")
|
|
)
|
|
|
|
foreach ($candidate in $candidates) {
|
|
if ($candidate -and (Test-Path -LiteralPath $candidate -PathType Container)) {
|
|
return (Resolve-Path -LiteralPath $candidate).Path
|
|
}
|
|
}
|
|
|
|
throw "Android SDK root was not found. Install command-line tools or set ANDROID_SDK_ROOT."
|
|
}
|
|
|
|
function Get-LatestAndroidSdkPackageDirectory {
|
|
param(
|
|
[Parameter(Mandatory=$true)][string]$SdkRoot,
|
|
[Parameter(Mandatory=$true)][string]$PackageName
|
|
)
|
|
|
|
$packageRoot = Join-Path $SdkRoot $PackageName
|
|
if (!(Test-Path -LiteralPath $packageRoot -PathType Container)) {
|
|
throw "Android SDK package directory not found: $packageRoot"
|
|
}
|
|
|
|
$packages = @(Get-ChildItem -LiteralPath $packageRoot -Directory |
|
|
Where-Object { $_.Name -match '^\d+(\.\d+)*$' } |
|
|
Sort-Object { [version]$_.Name } -Descending)
|
|
|
|
if ($packages.Count -eq 0) {
|
|
throw "No installed Android SDK package versions found under $packageRoot"
|
|
}
|
|
|
|
return $packages[0]
|
|
}
|
|
|
|
function Set-AndroidSdkToolchainEnvironment {
|
|
$sdkRoot = Get-AndroidSdkRoot
|
|
$ndk = Get-LatestAndroidSdkPackageDirectory -SdkRoot $sdkRoot -PackageName "ndk"
|
|
$cmake = Get-LatestAndroidSdkPackageDirectory -SdkRoot $sdkRoot -PackageName "cmake"
|
|
$cmakeCommand = Join-Path $cmake.FullName "bin\cmake.exe"
|
|
|
|
if (!(Test-Path -LiteralPath $cmakeCommand -PathType Leaf)) {
|
|
throw "Android SDK CMake executable not found: $cmakeCommand"
|
|
}
|
|
|
|
$env:ANDROID_HOME = $sdkRoot
|
|
$env:ANDROID_SDK_ROOT = $sdkRoot
|
|
$env:ANDROID_NDK_HOME = $ndk.FullName
|
|
$env:ANDROID_NDK_ROOT = $ndk.FullName
|
|
|
|
return [ordered]@{
|
|
sdkRoot = $sdkRoot
|
|
ndkVersion = $ndk.Name
|
|
ndkPath = $ndk.FullName
|
|
cmakeVersion = $cmake.Name
|
|
cmakeCommand = $cmakeCommand
|
|
}
|
|
}
|