Skip to content

Commit 0beb324

Browse files
author
Dimitar Kerezov
committed
Improve Windows setup script Android bits
Changes include: * In case `ANDROID_HOME` environment variable is not set, try to determine the correct path to `android-sdk` through `android.bat`'s location * Use `android.bat` executable relative to `android-sdk`, set in `ANDROID_HOME` environment variable, for sdk updates * Split android sdk updates into single command calls in order to avoid problems with license agreements
1 parent e869f23 commit 0beb324

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

setup/native-script.ps1

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,21 @@ Install "Google Chrome" "Installing Google Chrome (required to debug NativeScrip
7171
Install "Java Development Kit" "Installing Java Development Kit" "cinst jdk8 --force --yes"
7272

7373
Install "Android SDK" "Installing Android SDK" "cinst android-sdk --force --yes"
74-
75-
# setup android sdk
76-
echo yes | cmd /c "$env:localappdata\Android\android-sdk\tools\android" update sdk --filter "tools,platform-tools,android-23" --all --no-ui
77-
echo yes | cmd /c "$env:localappdata\Android\android-sdk\tools\android" update sdk --filter "build-tools-23.0.1,extra-android-m2repository" --all --no-ui
78-
7974
# setup environment
8075

8176
if (!$env:ANDROID_HOME) {
82-
[Environment]::SetEnvironmentVariable("ANDROID_HOME", "$env:localappdata\Android\android-sdk", "User")
83-
$env:ANDROID_HOME = "$env:localappdata\Android\android-sdk";
77+
# in case the user has `android` in the PATH, use it as base for setting ANDROID_HOME
78+
$androidExecutableEnvironmentPath = Get-Command android -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
79+
if ($androidExecutableEnvironmentPath -ne $null) {
80+
$androidHomeJoinedPath = [io.path]::combine($androidExecutableEnvironmentPath, "..", "..")
81+
$androidHome = Resolve-Path $androidHomeJoinedPath | Select-Object -ExpandProperty Path
82+
}
83+
else {
84+
$androidHome = "$env:localappdata\Android\android-sdk"
85+
}
86+
87+
$env:ANDROID_HOME = $androidHome;
88+
[Environment]::SetEnvironmentVariable("ANDROID_HOME", "$env:ANDROID_HOME", "User")
8489
}
8590

8691
if (!$env:JAVA_HOME) {
@@ -90,5 +95,16 @@ if (!$env:JAVA_HOME) {
9095
$env:JAVA_HOME = $javaHome;
9196
}
9297

98+
# setup android sdk
99+
# following commands are separated in case of having to answer to license agreements
100+
# the android tool will introduce a --accept-license option in subsequent releases
101+
$androidExecutable = [io.path]::combine($env:ANDROID_HOME, "tools", "android")
102+
echo y | cmd /c "$androidExecutable" update sdk --filter "tools" --all --no-ui
103+
echo y | cmd /c "$androidExecutable" update sdk --filter "platform-tools" --all --no-ui
104+
echo y | cmd /c "$androidExecutable" update sdk --filter "android-23" --all --no-ui
105+
echo y | cmd /c "$androidExecutable" update sdk --filter "build-tools-23.0.2" --all --no-ui
106+
echo y | cmd /c "$androidExecutable" update sdk --filter "extra-android-m2repository" --all --no-ui
107+
108+
93109
Write-Host -ForegroundColor Green "This script has modified your environment. You need to log off and log back on for the changes to take effect."
94110
Pause

0 commit comments

Comments
 (0)