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
USBIPD
on the host Windows 11, and adb
, Android Studio
on WSL 2. Follow the steps below in order.
$ sudo snap install android-studio --classic
$ nano ~/.bash_alises
alias studio="/snap/bin/android-studio > /dev/null 2>&1 &"
alias studio.="/snap/bin/android-studio . > /dev/null 2>&1 &"
$ android-studio
Settings > Language & Frameworks > Android SDK > SDK Tools > Android SDK Command-line Tools
https://developer.android.com/studio/run/win-usb
https://developer.samsung.com/android-usb-driver
$ winget install usbipd
$ sudo apt-get install adb -y
$ adb kill-server
$ adb start-server
$ 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.
Settings > About Phone > Software Information > Tap [Build Number] 7 times
Settings > About Phone > Developer Options > Turn on [USB Debugging] > Revoke USB debugging authorization
$ usbipd list
Connected:
BUSID VID:PID DEVICE STATE
1-1 1111:1111 S24, SAMSUNG Mobile USB Modem, SAMSUNG Mobile USB... Not shared
$ usbipd bind -b 1-1
$ usbipd attach --wsl=Ubuntu --busid=1-1
$ adb devices
List of devices attached
11111111111 device
- If the
adb devices
command in WSL 2 lists the connected Android devices, the setup is successful.
(Optional) Installing Flutter
- The
Flutter
development environment can be installed as follows. Devices connected as seen with the adb devices
command can also be confirmed with the flutter devices
command.
$ sudo snap install flutter --classic
$ flutter sdk-path
$ flutter doctor --android-licenses
$ 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!
$ 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