Skip to content

Instantly share code, notes, and snippets.

@robdmoore
Last active September 9, 2024 21:54
Show Gist options
  • Select an option

  • Save robdmoore/af6ec893c85364a97dc4 to your computer and use it in GitHub Desktop.

Select an option

Save robdmoore/af6ec893c85364a97dc4 to your computer and use it in GitHub Desktop.
Scripted/Automated installation script to set up Cordova/PhoneGap and Android on Windows
# Run this in an elevated PowerShell prompt
# I recommend you run these commands one-by-one since some of these programs seem a bit fragile to install, but feel free to yolo and script it all :)
# You can drop the -version parameters to get latest - I just know this combination works :)
# Install Chocolatey
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco # Check this works
# Install Java JDK
cinst java.jdk -version 7.0.60.1
# Set Java bin dir as first thing on path to override java.exe in Windows
[System.Environment]::SetEnvironmentVariable("PATH", [System.Environment]::GetEnvironmentVariable("JAVA_HOME","Machine") + "\bin;" + [System.Environment]::GetEnvironmentVariable("Path","Machine"), "Machine")
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
javac # Check this works
# Install ant
cinst apache.ant -version 1.8.4
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
ant # Check this works
# Install Android SDK
cinst android-sdk -version 22.6.2
[System.Environment]::SetEnvironmentVariable("PATH", [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";$env:LOCALAPPDATA\android\android-sdk\tools;$env:LOCALAPPDATA\android\android-sdk\platform-tools", "Machine")
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
# Update Android SDK bits
android list sdk <# This lists out all the things to install.
You want to choose the marked items (x) next to the following for the next command:
x1- Android SDK Tools, revision 23
x2- Android SDK Platform-tools, revision 20
x3- Android SDK Build-tools, revision 19.1
4- Documentation for Android SDK, API 19, revision 2
x5- SDK Platform Android 4.4.2, API 19, revision 3
...
Alternatively, you can just run "android" and use the GUI :)
#>
android update sdk --no-ui --filter "1,2,3,5" # You will need to enter "y[enter]" to accept the license terms
adb # Check this works
# Install nodejs
cinst nodejs.install
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
npm # Check this works
# Install Cordova
npm install -g cordova
# Check everything works
cordova create helloworld
cd helloworld
cordova platform install android
cordova build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment