Skip to content

Commit dbea46c

Browse files
author
PROGRESS\radeva
committed
fix: add more checks for correct ANDROID_HOME
- if ANDROID_HOME is set, check if the path is valid and clean it up if the path is not existing - add more path checks when updating Android SDK tools - add better coloring of messages
1 parent 3e8f20f commit dbea46c

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

common-script.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Create-AVD{
1111

1212
if ($installEmulatorAnswer -eq 'y') {
1313
if ((Read-Host "Do you want to install HAXM (Hardware accelerated Android emulator)?") -eq 'y') {
14-
Write-Host "Setting up Android SDK system-images;android-25;google_apis;x86..."
14+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK system-images;android-25;google_apis;x86..."
1515
echo y | cmd /c "$androidExecutable" "system-images;android-25;google_apis;x86"
1616

1717
echo y | cmd /c "$androidExecutable" "extras;intel;Hardware_Accelerated_Execution_Manager"
@@ -46,7 +46,7 @@ function Create-AVD{
4646
echo no | cmd /c $avdManagerExecutable $cmdArgList
4747

4848
if ($LASTEXITCODE -ne 0) {
49-
Write-Host -ForegroundColor Yellow "An error occurred while installing Android emulator."
49+
Write-Host -ForegroundColor Red "ERROR: An error occurred while installing Android emulator. Please, install it manually."
5050
}else{
5151
Write-Host -ForegroundColor Green "Android emulator is successfully installed."
5252
}

native-script.ps1

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Install($programName, $message, $script, $shouldExit) {
4343
} until ($script:answer -eq "y" -or $script:answer -eq "n" -or $script:answer -eq "a")
4444

4545
if ($script:answer -eq "n") {
46-
Write-Host -ForegroundColor Yellow "You have chosen not to install $($programName). Some features of NativeScript may not work correctly if you haven't already installed it"
46+
Write-Host -ForegroundColor Yellow "WARNING: You have chosen not to install $($programName). Some features of NativeScript may not work correctly if you haven't already installed it"
4747
return
4848
}
4949
}
@@ -76,12 +76,18 @@ Install "Google Chrome" "Installing Google Chrome (required to debug NativeScrip
7676

7777
Install "Java Development Kit" "Installing Java Development Kit" "choco upgrade jdk8 --force"
7878

79+
$androidHomePathExists = Test-Path $env:ANDROID_HOME
80+
if($androidHomePathExists -eq $False){
81+
[Environment]::SetEnvironmentVariable("ANDROID_HOME",$null,"User")
82+
}
83+
7984
Install "Android SDK" "Installing Android SDK" "cinst android-sdk --force --yes"
8085

8186
refreshenv
8287
# setup environment
8388

8489
if (!$env:ANDROID_HOME) {
90+
Write-Host -ForegroundColor DarkYellow "Setting up ANDROID_HOME"
8591
# in case the user has `android` in the PATH, use it as base for setting ANDROID_HOME
8692
$androidExecutableEnvironmentPath = Get-Command android -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
8793
if ($androidExecutableEnvironmentPath -ne $null) {
@@ -105,38 +111,46 @@ if (!$env:JAVA_HOME) {
105111
refreshenv
106112
}
107113

114+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK..."
115+
108116
# Update android-sdk tools in order to have avdmanager available and create AVDs later
109117
# NOTE: This step can be removed once chocolatey provides later version of Android SDK
110118
$androidToolsPath = [io.path]::combine($env:ANDROID_HOME, "tools")
111119
$androidToolsOldPath = [io.path]::combine($env:ANDROID_HOME, "toolsOld")
112-
Copy-Item "$androidToolsPath" "$androidToolsOldPath" -recurse
113-
echo y | cmd /c "%ANDROID_HOME%\toolsOld\bin\sdkmanager.bat" "tools"
114-
Remove-Item "$androidToolsOldPath" -Force -Recurse
120+
121+
$androidToolsPathExists = Test-Path $androidToolsPath
122+
if($androidToolsPathExists -eq $True){
123+
Write-Host -ForegroundColor DarkYellow "Updating Android SDK tools..."
124+
Copy-Item "$androidToolsPath" "$androidToolsOldPath" -recurse
125+
echo y | cmd /c "%ANDROID_HOME%\toolsOld\bin\sdkmanager.bat" "tools"
126+
Remove-Item "$androidToolsOldPath" -Force -Recurse
127+
} else {
128+
Write-Host -ForegroundColor Red "ERROR: Failed to update Android SDK tools. This is a blocker to install default emulator, so please update manually once this installation has finished."
129+
}
115130

116131
# add repositories.cfg if it is not created
117132
$repositoriesConfigPath = [io.path]::combine($env:USERPROFILE, ".android", "repositories.cfg")
118133
$pathExists = Test-Path $repositoriesConfigPath
119134
if($pathExists -eq $False){
120-
Write-Host "Creating file $repositoriesConfigPath ..."
135+
Write-Host -ForegroundColor DarkYellow "Creating file $repositoriesConfigPath ..."
121136
New-Item $repositoriesConfigPath -type file
122137
}
123138

124139
# setup android sdk
125140
# following commands are separated in case of having to answer to license agreements
126141
$androidExecutable = [io.path]::combine($env:ANDROID_HOME, "tools", "bin", "sdkmanager")
127142

128-
Write-Host "Setting up Android SDK..."
129-
Write-Host "Setting up Android SDK platform-tools..."
143+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK platform-tools..."
130144
echo y | cmd /c "$androidExecutable" "platform-tools"
131-
Write-Host "Setting up Android SDK build-tools;25.0.2..."
145+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK build-tools;25.0.2..."
132146
echo y | cmd /c "$androidExecutable" "build-tools;25.0.2"
133-
Write-Host "Setting up Android SDK platforms;android-25..."
147+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK platforms;android-25..."
134148
echo y | cmd /c "$androidExecutable" "platforms;android-25"
135-
Write-Host "Setting up Android SDK extras;android;m2repository..."
149+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK extras;android;m2repository..."
136150
echo y | cmd /c "$androidExecutable" "extras;android;m2repository"
137-
Write-Host "Setting up Android SDK extras;google;m2repository..."
151+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK extras;google;m2repository..."
138152
echo y | cmd /c "$androidExecutable" "extras;google;m2repository"
139-
Write-Host "FINISHED setting up Android SDK."
153+
Write-Host -ForegroundColor DarkYellow "FINISHED setting up Android SDK."
140154

141155
# Setup Default Emulator
142156
iex ((new-object net.webclient).DownloadString($scriptCommonUrl))

0 commit comments

Comments
 (0)