Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jukefr/da9d44c71c46390b6aa7ca7af1dc4b6e to your computer and use it in GitHub Desktop.
Save jukefr/da9d44c71c46390b6aa7ca7af1dc4b6e to your computer and use it in GitHub Desktop.
Ionic Android Development on WSL2 (Windows Subsystem for Linux)

Ionic Android Development on WSL2

This setup is assuming that GUI Linux apps can run in your WSL2.

Installing the required software

Execute the following commands to install Node, npm, git, Java, Ionic CLI:

cd ~
sudo apt update
sudo apt upgrade

# Replace bash if you are using other shells e.g. zsh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
nvm install --lts
nvm use --lts

npm install -g @ionic/cli

sudo apt install git
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git config --global core.autocrlf input

sudo apt-get update
sudo apt remove openjdk*
sudo apt install openjdk-17-jdk

Downloading Android Studio

mkdir -p $HOME/Downloads && cd "$_"
wget https://r2---sn-npoe7nss.gvt1.com/edgedl/android/studio/ide-zips/2021.3.1.16/android-studio-2021.3.1.16-linux.tar.gz
mkdir -p $HOME/Applications && cd "$_"
tar xfv $(ls -1t $HOME/Downloads/android-studio-* | head -n1)

Note: you can get an updated Android Studio link from https://developer.android.com/studio/#downloads

Install Android SDK and Tools using Android Studio

Run the Android Studio and install the necessary tools with the GUI wizard

$HOME/Applications/android-studio/bin/studio.sh

Adding the Android SDK to your PATH

Add the following to your .profile (or .zshrc if you use zsh):

# Add Android SDK to PATH
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export CAPACITOR_ANDROID_STUDIO_PATH=$HOME/Applications/android-studio/bin/studio.sh
PATH="$HOME/Applications/android-studio/bin:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/emulator:$PATH"
export PATH

Install VM Emulator

sudo apt install qemu-kvm
sudo adduser $USER kvm

Create a new file /etc/wsl.conf with the following content:

[boot]
command = /bin/bash -c 'chown root:kvm /dev/kvm && chmod 660 /dev/kvm'

Reboot your machine.

Open Android Studio

  • Run ionic cap add android for new project
  • Run ionic cap sync android for existing project
  • Run ionic cap open android

Then edit the device by clicking the pen icon on the right side panel and select the appropriate SDK API version, currently it defaults to 34 but Ionic says to use 33 (tiramisu)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment