Setting Up Android Development Environment on WSL 2

Overview
- This guide outlines how to set up an Android app development environment in WSL 2 with Windows 11 as the host machine and connect Android devices to it.
Installing Android Studio, ADB, USBIPD
- To develop Android apps in WSL 2, you need to install
USBIPDon the host Windows 11, andadb,Android Studioon WSL 2. Follow the steps below in order.
# [WSL 2] Install Android Studio
$ sudo snap install android-studio --classic
# [WSL 2] Create Aliases
$ nano ~/.bash_alises
alias studio="/snap/bin/android-studio > /dev/null 2>&1 &"
alias studio.="/snap/bin/android-studio . > /dev/null 2>&1 &"
# [WSL 2] Run Android Studio
$ android-studio
# [WSL 2] On first launch of Android Studio, follow the prompts to install Android SDK Command-line Tools
Settings > Language & Frameworks > Android SDK > SDK Tools > Android SDK Command-line Tools
# [Windows 11] Install Android ADB Interface driver on Windows 11
https://developer.android.com/studio/run/win-usb
https://developer.samsung.com/android-usb-driver
# [Windows 11] Install USBIPD on Windows 11
$ winget install usbipd
# [WSL 2] Install adb in WSL 2
$ sudo apt-get install adb -y
$ adb kill-server
$ adb start-server
# [WSL 2] Verify adb is running
$ adb devices
List of devices attached
Connecting Android Device
- WSL 2 does not recognize Android devices connected to the host PC. By using
USBIPD, USB traffic can be forwarded to WSL 2 for device recognition. Follow the steps below in order.
# Activate developer mode on the Android device and connect to PC via cable
Settings > About Phone > Software Information > Tap [Build Number] 7 times
Settings > About Phone > Developer Options > Turn on [USB Debugging] > Revoke USB debugging authorization
# Check connected Android devices on Windows 11
$ usbipd list
Connected:
BUSID VID:PID DEVICE STATE
1-1 1111:1111 S24, SAMSUNG Mobile USB Modem, SAMSUNG Mobile USB... Not shared
# Forward connected Android device to WSL 2 on Windows 11
# Confirm permission on the Android device when the authorization window appears
$ usbipd bind -b 1-1
$ usbipd attach --wsl=Ubuntu --busid=1-1
# Verify the connected Android device in WSL 2
$ adb devices
List of devices attached
11111111111 device
- If the
adb devicescommand in WSL 2 lists the connected Android devices, the setup is successful.
(Optional) Installing Flutter
- The
Flutterdevelopment environment can be installed as follows. Devices connected as seen with theadb devicescommand can also be confirmed with theflutter devicescommand.
# Install Flutter
$ sudo snap install flutter --classic
$ flutter sdk-path
$ flutter doctor --android-licenses
# Verify the installation
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.4, on Ubuntu 22.04.4 LTS 5.15.146.1-microsoft-standard-WSL2, locale C.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.2)
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!
# Check Flutter connected devices
$ flutter devices
Found 3 connected devices:
SM S921N (mobile) • 11111111111 • android-arm64 • Android 14 (API 34)
Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.4 LTS 5.15.146.1-microsoft-standard-WSL2
Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.58
References
Comments
Join the discussionNo comments yet. Be the first to comment.




