8
8
param (
9
9
[switch ] $SilentMode
10
10
)
11
+
12
+ $scriptUrl = " https://www.nativescript.org/setup/win"
13
+ $scriptCommonUrl = " https://www.nativescript.org/setup/win-common"
14
+
11
15
# Check if latest .NET framework installed is at least 4
12
16
$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
13
17
$latestDotNetVersion = $dotNetVersions.GetEnumerator () | Sort-Object Version | Select-Object - Last 1
@@ -24,7 +28,7 @@ if ($latestDotNetMajorNumber -lt 4) {
24
28
# Self-elevate
25
29
$isElevated = ([Security.Principal.WindowsPrincipal ] [Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ]" Administrator" )
26
30
if (-not $isElevated ) {
27
- start-process - FilePath PowerShell.exe - Verb Runas - Wait - ArgumentList " -NoProfile -ExecutionPolicy Bypass -Command iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/NativeScript/nativescript-cli/production/setup/native-script.ps1 '))"
31
+ start-process - FilePath PowerShell.exe - Verb Runas - Wait - ArgumentList ( " -NoProfile -ExecutionPolicy Bypass -Command iex ((new-object net.webclient).DownloadString('" + $scriptUrl + " '))" )
28
32
exit 0
29
33
}
30
34
@@ -39,7 +43,7 @@ function Install($programName, $message, $script, $shouldExit) {
39
43
} until ($script :answer -eq " y" -or $script :answer -eq " n" -or $script :answer -eq " a" )
40
44
41
45
if ($script :answer -eq " n" ) {
42
- 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"
43
47
return
44
48
}
45
49
}
@@ -66,16 +70,28 @@ if ((Get-Command "cinst" -ErrorAction SilentlyContinue) -eq $null) {
66
70
exit 1
67
71
}
68
72
69
- # Install dependenciess with Chocolatey
73
+ # Install dependencies with Chocolatey
70
74
71
75
Install " Google Chrome" " Installing Google Chrome (required to debug NativeScript apps)" " cinst googlechrome --force --yes"
72
76
73
- Install " Java Development Kit" " Installing Java Development Kit" " cinst jdk8 --force --yes"
77
+ Install " Java Development Kit" " Installing Java Development Kit" " choco upgrade jdk8 --force"
78
+
79
+ $androidHomePathExists = $False
80
+ if ($env: ANDROID_HOME ){
81
+ $androidHomePathExists = Test-Path $env: ANDROID_HOME
82
+ }
83
+
84
+ if ($androidHomePathExists -eq $False ){
85
+ [Environment ]::SetEnvironmentVariable(" ANDROID_HOME" , $null , " User" )
86
+ }
74
87
75
88
Install " Android SDK" " Installing Android SDK" " cinst android-sdk --force --yes"
89
+
90
+ refreshenv
76
91
# setup environment
77
92
78
93
if (! $env: ANDROID_HOME ) {
94
+ Write-Host - ForegroundColor DarkYellow " Setting up ANDROID_HOME"
79
95
# in case the user has `android` in the PATH, use it as base for setting ANDROID_HOME
80
96
$androidExecutableEnvironmentPath = Get-Command android - ErrorAction SilentlyContinue | Select-Object - ExpandProperty Definition
81
97
if ($androidExecutableEnvironmentPath -ne $null ) {
@@ -88,36 +104,71 @@ if (!$env:ANDROID_HOME) {
88
104
89
105
$env: ANDROID_HOME = $androidHome ;
90
106
[Environment ]::SetEnvironmentVariable(" ANDROID_HOME" , " $env: ANDROID_HOME " , " User" )
107
+ refreshenv
91
108
}
92
109
93
110
if (! $env: JAVA_HOME ) {
94
111
$curVer = (Get-ItemProperty " HKLM:\SOFTWARE\JavaSoft\Java Development Kit" ).CurrentVersion
95
112
$javaHome = (Get-ItemProperty " HKLM:\Software\JavaSoft\Java Development Kit\$curVer " ).JavaHome
96
113
[Environment ]::SetEnvironmentVariable(" JAVA_HOME" , $javaHome , " User" )
97
114
$env: JAVA_HOME = $javaHome ;
115
+ refreshenv
116
+ }
117
+
118
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK..."
119
+
120
+ # Update android-sdk tools in order to have avdmanager available and create AVDs later
121
+ # NOTE: This step can be removed once chocolatey provides later version of Android SDK
122
+ $androidToolsPath = [io.path ]::combine($env: ANDROID_HOME , " tools" )
123
+ $androidToolsOldPath = [io.path ]::combine($env: ANDROID_HOME , " toolsOld" )
124
+
125
+ $androidToolsPathExists = $False
126
+ if ($androidToolsPath ){
127
+ $androidToolsPathExists = Test-Path $androidToolsPath
128
+ }
129
+
130
+ if ($androidToolsPathExists -eq $True ){
131
+ Write-Host - ForegroundColor DarkYellow " Updating Android SDK tools..."
132
+ Copy-Item " $androidToolsPath " " $androidToolsOldPath " - recurse
133
+ # Do NOT auto-accept license with `echo y` since the command requires acceptance of MULTIPLE licenses on a clean machine which breaks in this case
134
+ cmd / c " %ANDROID_HOME%\toolsOld\bin\sdkmanager.bat" " tools"
135
+ Remove-Item " $androidToolsOldPath " - Force - Recurse
136
+ } else {
137
+ 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."
138
+ }
139
+
140
+ # add repositories.cfg if it is not created
141
+ $repositoriesConfigPath = [io.path ]::combine($env: USERPROFILE , " .android" , " repositories.cfg" )
142
+
143
+ $pathExists = $False
144
+ if ($repositoriesConfigPath ){
145
+ $pathExists = Test-Path $repositoriesConfigPath
146
+ }
147
+
148
+ if ($pathExists -eq $False ){
149
+ Write-Host - ForegroundColor DarkYellow " Creating file $repositoriesConfigPath ..."
150
+ New-Item $repositoriesConfigPath - type file
98
151
}
99
152
100
153
# setup android sdk
101
154
# following commands are separated in case of having to answer to license agreements
102
155
$androidExecutable = [io.path ]::combine($env: ANDROID_HOME , " tools" , " bin" , " sdkmanager" )
156
+
157
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK platform-tools..."
103
158
echo y | cmd / c " $androidExecutable " " platform-tools"
104
- echo y | cmd / c " $androidExecutable " " tools"
159
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK build- tools;25.0.2... "
105
160
echo y | cmd / c " $androidExecutable " " build-tools;25.0.2"
161
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK platforms;android-25..."
106
162
echo y | cmd / c " $androidExecutable " " platforms;android-25"
163
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK extras;android;m2repository..."
107
164
echo y | cmd / c " $androidExecutable " " extras;android;m2repository"
165
+ Write-Host - ForegroundColor DarkYellow " Setting up Android SDK extras;google;m2repository..."
108
166
echo y | cmd / c " $androidExecutable " " extras;google;m2repository"
167
+ Write-Host - ForegroundColor DarkYellow " FINISHED setting up Android SDK."
109
168
110
- if ((Read-Host " Do you want to install Android emulator?" ) -eq ' y' ) {
111
- if ((Read-Host " Do you want to install HAXM (Hardware accelerated Android emulator)?" ) -eq ' y' ) {
112
- echo y | cmd / c " $androidExecutable " " extras;intel;Hardware_Accelerated_Execution_Manager"
113
- $haxmSilentInstaller = [io.path ]::combine($env: ANDROID_HOME , " extras" , " intel" , " Hardware_Accelerated_Execution_Manager" , " silent_install.bat" )
114
- cmd / c " $haxmSilentInstaller "
115
- echo y | cmd / c " $androidExecutable " " system-images;android-25;google_apis;x86"
116
- }
117
- else {
118
- echo y | cmd / c " $androidExecutable " " system-images;android-25;google_apis;armeabi-v7a"
119
- }
120
- }
169
+ # Setup Default Emulator
170
+ iex ((new-object net.webclient).DownloadString($scriptCommonUrl ))
171
+ Create- AVD
121
172
122
173
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."
123
- Pause
174
+ Pause
0 commit comments