Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save steveclarke/d988d89e8cdf51a8a5766d69ecb07e7b to your computer and use it in GitHub Desktop.
Save steveclarke/d988d89e8cdf51a8a5766d69ecb07e7b to your computer and use it in GitHub Desktop.

Install Android SDK CLI Ubuntu 20.04 WSL2 (Work in Progress)

Install Java 8

sudo apt install openjdk-8-jdk-headless

Android SDK

wget https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip
mkdir -p Android/Sdk
unzip commandlinetools-linux-6200805_latest.zip -d Android/Sdk

export ANDROID_HOME=$HOME/Android/Sdk
# Make sure emulator path comes before tools. Had trouble on Ubuntu with emulator from /tools being loaded
# instead of the one from /emulator
export PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

sdkmanager --sdk_root=${ANDROID_HOME} "tools"

sdkmanager --update
sdkmanager --list
sdkmanager "build-tools;28.0.3" "platform-tools" "platforms;android-28" "tools"
sdkmanager --licenses

sudo apt install gradle

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

Used a combinaton of these gists: https://gist.github.com/fedme/fd42caec2e5a7e93e12943376373b7d0 https://gist.github.com/jjvillavicencio/18feb09f0e93e017a861678bc638dcb0

Background on the update to command line tools from android sdk https://stackoverflow.com/a/61176718

@mirao
Copy link

mirao commented Mar 11, 2023

Just in case you want to install Android Studio with functional GUI from snap in Ubuntu 22.04 in WSL2 (Windows 11), follow these steps:

  1. Enable systemd
  2. Run this
sudo snap install android-studio --classic
sudo apt install openjdk-11-jre-headless libxrender1 libxtst6 libxi6

@bswck
Copy link

bswck commented Aug 15, 2023

sudo apt install openjdk-17-jdk for the latest release.

@sazonov-src
Copy link

+++

@luskan
Copy link

luskan commented Jun 15, 2025

usbipd worked for me to share android device on usb with wsl2, it is visible in android studio run from wsl2 using vcxsrv. Here is a walkthrough:

Enable USB Debugging via USB/IP (USB Passthrough to WSL2)(win 10/11)

Install usbipd-win on Windows via PowerShell (or directly from github msi):

winget install dorssel.usbipd-win

In Ubuntu WSL2, install the client tools:

sudo apt install linux-tools-virtual hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*/usbip 20

Share the USB device from Windows: Open PowerShell as Administrator on Windows and list USB devices:

usbipd list

This will show a list of connected USB devices with their BUSID

Find the entry corresponding to your Android device (by vendor name or ID).

Bind and Attach the device to WSL2: Still in PowerShell, first bind the device (makes it shareable) and then attach it to WSL:

usbipd attach --busid --wsl

Replace with the ID from the list (e.g. usbipd wsl attach --busid 4-4 for bus 4-4)

This command can ask you to run a different command in admin ps.

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