Skip to content

Commit 8979876

Browse files
authored
Merge pull request #7 from NativeScript/radeva/update-setup-scripts
docs(win-install): update installation script
2 parents 798122b + 3e9a3d9 commit 8979876

File tree

3 files changed

+135
-17
lines changed

3 files changed

+135
-17
lines changed

common-script.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
function Create-AVD{
2+
$androidExecutable = [io.path]::combine($env:ANDROID_HOME, "tools", "bin", "sdkmanager")
3+
$avdManagerExecutable = [io.path]::combine($env:ANDROID_HOME, "tools", "bin", "avdmanager")
4+
5+
# Setup Default Emulator
6+
$installEmulatorAnswer = ''
7+
Do {
8+
$installEmulatorAnswer = (Read-Host "Do you want to install Android emulator? (Y)es/(N)o").ToLower()
9+
}
10+
While ($installEmulatorAnswer -ne 'y' -and $installEmulatorAnswer -ne 'n')
11+
12+
if ($installEmulatorAnswer -eq 'y') {
13+
if ((Read-Host "Do you want to install HAXM (Hardware accelerated Android emulator)?") -eq 'y') {
14+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK system-images;android-25;google_apis;x86..."
15+
echo y | cmd /c "$androidExecutable" "system-images;android-25;google_apis;x86"
16+
17+
echo y | cmd /c "$androidExecutable" "extras;intel;Hardware_Accelerated_Execution_Manager"
18+
$haxmSilentInstaller = [io.path]::combine($env:ANDROID_HOME, "extras", "intel", "Hardware_Accelerated_Execution_Manager", "silent_install.bat")
19+
cmd /c "$haxmSilentInstaller"
20+
21+
if ($LASTEXITCODE -ne 0) {
22+
Write-Host -ForegroundColor Yellow "WARNING: Failed to install HAXM in silent mode. Starting interactive mode."
23+
$haxmInstaller = [io.path]::combine($env:ANDROID_HOME, "extras", "intel", "Hardware_Accelerated_Execution_Manager", "intelhaxm-android.exe")
24+
cmd /c "$haxmInstaller"
25+
}
26+
27+
$cmdArgList = @(
28+
"create",
29+
"avd",
30+
"-n","Emulator-Api25-Default-haxm",
31+
"-k",'"system-images;android-25;google_apis;x86"'
32+
)
33+
}
34+
else {
35+
Write-Host "Setting up Android SDK system-images;android-25;google_apis;armeabi-v7a..."
36+
echo y | cmd /c "$androidExecutable" "system-images;android-25;google_apis;armeabi-v7a"
37+
38+
$cmdArgList = @(
39+
"create",
40+
"avd",
41+
"-n","Emulator-Api25-Default",
42+
"-k",'"system-images;android-25;google_apis;armeabi-v7a"'
43+
)
44+
}
45+
46+
echo no | cmd /c $avdManagerExecutable $cmdArgList
47+
48+
if ($LASTEXITCODE -ne 0) {
49+
Write-Host -ForegroundColor Red "ERROR: An error occurred while installing Android emulator. Please, install it manually."
50+
}else{
51+
Write-Host -ForegroundColor Green "Android emulator is successfully installed."
52+
}
53+
}
54+
}

create-avd-script.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$scriptUrl = "https://www.nativescript.org/setup/win-avd"
2+
$scriptCommonUrl = "https://www.nativescript.org/setup/win-common"
3+
4+
# Self-elevate
5+
$isElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")
6+
if (-not $isElevated) {
7+
start-process -FilePath PowerShell.exe -Verb Runas -Wait -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -Command iex ((new-object net.webclient).DownloadString('" + $scriptUrl + "'))")
8+
exit 0
9+
}
10+
11+
iex ((new-object net.webclient).DownloadString($scriptCommonUrl))
12+
Create-AVD
13+
exit 0

native-script.ps1

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
param(
99
[switch] $SilentMode
1010
)
11+
12+
$scriptUrl = "https://www.nativescript.org/setup/win"
13+
$scriptCommonUrl = "https://www.nativescript.org/setup/win-common"
14+
1115
# Check if latest .NET framework installed is at least 4
1216
$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
1317
$latestDotNetVersion = $dotNetVersions.GetEnumerator() | Sort-Object Version | Select-Object -Last 1
@@ -24,7 +28,7 @@ if ($latestDotNetMajorNumber -lt 4) {
2428
# Self-elevate
2529
$isElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")
2630
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 + "'))")
2832
exit 0
2933
}
3034

@@ -39,7 +43,7 @@ function Install($programName, $message, $script, $shouldExit) {
3943
} until ($script:answer -eq "y" -or $script:answer -eq "n" -or $script:answer -eq "a")
4044

4145
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"
4347
return
4448
}
4549
}
@@ -66,16 +70,28 @@ if ((Get-Command "cinst" -ErrorAction SilentlyContinue) -eq $null) {
6670
exit 1
6771
}
6872

69-
# Install dependenciess with Chocolatey
73+
# Install dependencies with Chocolatey
7074

7175
Install "Google Chrome" "Installing Google Chrome (required to debug NativeScript apps)" "cinst googlechrome --force --yes"
7276

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+
}
7487

7588
Install "Android SDK" "Installing Android SDK" "cinst android-sdk --force --yes"
89+
90+
refreshenv
7691
# setup environment
7792

7893
if (!$env:ANDROID_HOME) {
94+
Write-Host -ForegroundColor DarkYellow "Setting up ANDROID_HOME"
7995
# in case the user has `android` in the PATH, use it as base for setting ANDROID_HOME
8096
$androidExecutableEnvironmentPath = Get-Command android -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
8197
if ($androidExecutableEnvironmentPath -ne $null) {
@@ -88,36 +104,71 @@ if (!$env:ANDROID_HOME) {
88104

89105
$env:ANDROID_HOME = $androidHome;
90106
[Environment]::SetEnvironmentVariable("ANDROID_HOME", "$env:ANDROID_HOME", "User")
107+
refreshenv
91108
}
92109

93110
if (!$env:JAVA_HOME) {
94111
$curVer = (Get-ItemProperty "HKLM:\SOFTWARE\JavaSoft\Java Development Kit").CurrentVersion
95112
$javaHome = (Get-ItemProperty "HKLM:\Software\JavaSoft\Java Development Kit\$curVer").JavaHome
96113
[Environment]::SetEnvironmentVariable("JAVA_HOME", $javaHome, "User")
97114
$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
98151
}
99152

100153
# setup android sdk
101154
# following commands are separated in case of having to answer to license agreements
102155
$androidExecutable = [io.path]::combine($env:ANDROID_HOME, "tools", "bin", "sdkmanager")
156+
157+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK platform-tools..."
103158
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..."
105160
echo y | cmd /c "$androidExecutable" "build-tools;25.0.2"
161+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK platforms;android-25..."
106162
echo y | cmd /c "$androidExecutable" "platforms;android-25"
163+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK extras;android;m2repository..."
107164
echo y | cmd /c "$androidExecutable" "extras;android;m2repository"
165+
Write-Host -ForegroundColor DarkYellow "Setting up Android SDK extras;google;m2repository..."
108166
echo y | cmd /c "$androidExecutable" "extras;google;m2repository"
167+
Write-Host -ForegroundColor DarkYellow "FINISHED setting up Android SDK."
109168

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
121172

122173
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

Comments
 (0)