10
10
)
11
11
12
12
$scriptUrl = " https://www.nativescript.org/setup/win"
13
- $scriptCommonUrl = " https://www.nativescript.org/setup/win-common"
14
13
15
14
# Check if latest .NET framework installed is at least 4
16
15
$dotNetVersions = Get-ChildItem ' HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' - recurse | Get-ItemProperty - name Version, Release - EA 0 | Where { $_.PSChildName -match ' ^(?!S)\p{L}' } | Select Version
@@ -37,7 +36,7 @@ $script:answer = if ($SilentMode) {"a"} else {""}
37
36
function Install ($programName , $message , $script , $shouldExit ) {
38
37
if ($script :answer -ne " a" ) {
39
38
Write-Host - ForegroundColor Green " Allow the script to install $ ( $programName ) ?"
40
- Write-Host " Tip: Note that if you type a you won't be prompted for subsequent installations"
39
+ Write-Host " Tip: Note that if you type A you won't be prompted for subsequent installations"
41
40
do {
42
41
$script :answer = (Read-Host " (Y)es/(N)o/(A)ll" ).ToLower()
43
42
} until ($script :answer -eq " y" -or $script :answer -eq " n" -or $script :answer -eq " a" )
@@ -60,7 +59,6 @@ function Pause {
60
59
[void ][System.Console ]::ReadKey($true )
61
60
}
62
61
63
- # Actually installing all other dependencies
64
62
# Install Chocolatey
65
63
Install " Chocolatey (It's mandatory for the rest of the script)" " Installing Chocolatey" " iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
66
64
@@ -70,12 +68,35 @@ if ((Get-Command "cinst" -ErrorAction SilentlyContinue) -eq $null) {
70
68
exit 1
71
69
}
72
70
73
- # Install dependencies with Chocolatey
71
+ # Refresh Environment Variables
72
+ refreshenv
74
73
74
+ # Install dependencies with Chocolatey
75
75
Install " Google Chrome" " Installing Google Chrome (required to debug NativeScript apps)" " cinst googlechrome --force --yes"
76
76
77
- Install " Java Development Kit" " Installing Java Development Kit" " choco upgrade jdk8 --force"
77
+ # Install OpenJDK after Android SDK, as currently installing the Android SDK also installs the Oracle Java 1.8 version.
78
+ Install " Java Development Kit (OpenJDK)" " Installing Java Development Kit (OpenJDK)" " choco upgrade adoptopenjdk --version 8.192 --force --yes"
79
+
80
+ # For some reason refreshing the environment variables is not working with Chocolatey.
81
+ # To force it, refresh the $PROFILE, as shown here: https://stackoverflow.com/a/46760714/3357767
82
+ $env: ChocolateyInstall = Convert-Path " $ ( (Get-Command choco).path) \..\.."
83
+ Import-Module " $env: ChocolateyInstall \helpers\chocolateyProfile.psm1"
84
+ refreshenv
85
+
86
+ if (! $env: JAVA_HOME ) {
87
+ $openJdkLocation = " C:\Program Files\OpenJDK" ;
88
+ $openJdkLocationExists = Test-Path $openJdkLocation ;
89
+
90
+ if ($openJdkLocationExists -eq $True ) {
91
+ # We should never come here, the installation of OpenJDK should set the variable
92
+ Write-Host - ForegroundColor DarkYellow " Setting up JAVA_HOME to $openJdkLocation " ;
93
+ [Environment ]::SetEnvironmentVariable(" JAVA_HOME" , $openJdkLocation , " User" );
94
+ $env: JAVA_HOME = $openJdkLocation ;
95
+ refreshenv;
96
+ }
97
+ }
78
98
99
+ # Check ANDROID_HOME
79
100
$androidHomePathExists = $False
80
101
if ($env: ANDROID_HOME ){
81
102
$androidHomePathExists = Test-Path $env: ANDROID_HOME
@@ -85,11 +106,10 @@ if($androidHomePathExists -eq $False){
85
106
[Environment ]::SetEnvironmentVariable(" ANDROID_HOME" , $null , " User" )
86
107
}
87
108
109
+ # Install Android SDK
88
110
Install " Android SDK" " Installing Android SDK" " cinst android-sdk --force --yes"
89
111
90
- refreshenv
91
- # setup environment
92
-
112
+ # Set ANDROID_HOME
93
113
if (! $env: ANDROID_HOME ) {
94
114
Write-Host - ForegroundColor DarkYellow " Setting up ANDROID_HOME"
95
115
# in case the user has `android` in the PATH, use it as base for setting ANDROID_HOME
@@ -107,14 +127,6 @@ if (!$env:ANDROID_HOME) {
107
127
refreshenv
108
128
}
109
129
110
- if (! $env: JAVA_HOME ) {
111
- $curVer = (Get-ItemProperty " HKLM:\SOFTWARE\JavaSoft\Java Development Kit" ).CurrentVersion
112
- $javaHome = (Get-ItemProperty " HKLM:\Software\JavaSoft\Java Development Kit\$curVer " ).JavaHome
113
- [Environment ]::SetEnvironmentVariable(" JAVA_HOME" , $javaHome , " User" )
114
- $env: JAVA_HOME = $javaHome ;
115
- refreshenv
116
- }
117
-
118
130
Write-Host - ForegroundColor DarkYellow " Setting up Android SDK..."
119
131
120
132
# Update android-sdk tools in order to have avdmanager available and create AVDs later
@@ -156,19 +168,62 @@ $androidExecutable = [io.path]::combine($env:ANDROID_HOME, "tools", "bin", "sdkm
156
168
157
169
Write-Host - ForegroundColor DarkYellow " Setting up Android SDK platform-tools..."
158
170
echo y | cmd / c " $androidExecutable " " platform-tools"
159
- Write-Host - ForegroundColor DarkYellow " Setting up Android SDK build-tools;27 .0.3..."
160
- echo y | cmd / c " $androidExecutable " " build-tools;27 .0.3"
161
- Write-Host - ForegroundColor DarkYellow " Setting up Android SDK platforms;android-25 ..."
162
- echo y | cmd / c " $androidExecutable " " platforms;android-25 "
171
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK build-tools;28 .0.3..."
172
+ echo y | cmd / c " $androidExecutable " " build-tools;28 .0.3"
173
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK platforms;android-28 ..."
174
+ echo y | cmd / c " $androidExecutable " " platforms;android-28 "
163
175
Write-Host - ForegroundColor DarkYellow " Setting up Android SDK extras;android;m2repository..."
164
176
echo y | cmd / c " $androidExecutable " " extras;android;m2repository"
165
177
Write-Host - ForegroundColor DarkYellow " Setting up Android SDK extras;google;m2repository..."
166
178
echo y | cmd / c " $androidExecutable " " extras;google;m2repository"
167
179
Write-Host - ForegroundColor DarkYellow " FINISHED setting up Android SDK."
168
180
169
181
# Setup Default Emulator
170
- iex ((new-object net.webclient).DownloadString($scriptCommonUrl ))
171
- Create- AVD
182
+ $androidExecutable = [io.path ]::combine($env: ANDROID_HOME , " tools" , " bin" , " sdkmanager" )
183
+ $avdManagerExecutable = [io.path ]::combine($env: ANDROID_HOME , " tools" , " bin" , " avdmanager" )
184
+
185
+ # Emulator will not be installed in silent mode since Intel HAXM fails to install in silent mode.
186
+ $installEmulatorAnswer = if ($SilentMode ) {" n" } else {
187
+ Do {
188
+ $installEmulatorAnswer = (Read-Host " Do you want to install Android emulator? (Y)es/(N)o" ).ToLower()
189
+ }
190
+ While ($installEmulatorAnswer -ne ' y' -and $installEmulatorAnswer -ne ' n' )
191
+ }
192
+
193
+ if ($installEmulatorAnswer -eq ' y' ) {
194
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK system-images;android-28;google_apis;x86..."
195
+ echo y | cmd / c " $androidExecutable " " system-images;android-28;google_apis;x86"
196
+
197
+ echo y | cmd / c " $androidExecutable " " extras;intel;Hardware_Accelerated_Execution_Manager"
198
+ $haxmSilentInstaller = [io.path ]::combine($env: ANDROID_HOME , " extras" , " intel" , " Hardware_Accelerated_Execution_Manager" , " silent_install.bat" )
199
+ cmd / c " $haxmSilentInstaller "
200
+
201
+ if ($LASTEXITCODE -ne 0 ) {
202
+ Write-Host - ForegroundColor Yellow " WARNING: Failed to install HAXM in silent mode. Starting interactive mode."
203
+ $haxmInstaller = [io.path ]::combine($env: ANDROID_HOME , " extras" , " intel" , " Hardware_Accelerated_Execution_Manager" , " intelhaxm-android.exe" )
204
+ cmd / c " $haxmInstaller "
205
+ }
206
+
207
+ $cmdArgList = @ (
208
+ " create" ,
209
+ " avd" ,
210
+ " -n" , " Emulator-Api28-Default" ,
211
+ " -k" , ' "system-images;android-28;google_apis;x86"'
212
+ )
213
+
214
+ echo no | cmd / c $avdManagerExecutable $cmdArgList
215
+
216
+ if ($LASTEXITCODE -ne 0 ) {
217
+ Write-Host - ForegroundColor Red " ERROR: An error occurred while installing Android emulator. Please, install it manually."
218
+ }else {
219
+ Write-Host - ForegroundColor Green " Android emulator is successfully installed."
220
+ }
221
+ }
222
+
223
+ # Refresh Environment Variables
224
+ refreshenv
172
225
173
226
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."
227
+ if (-Not $SilentMode ) {
174
228
Pause
229
+ }
0 commit comments