Developing Flutter with Physical Devices on WSL2 — Windows 10

Josh Kautz
4 min readJan 14, 2022

--

Welcome! If you haven’t yet installed Flutter on WSL2, be sure to check out the previous article that steps through that process…

… Congratulations! Now you’re ready to get developing with Flutter on WSL2 for Windows 10. We will be running some Bash commands on WSL2, but it should be very simple.

Connect to Android device (Wireless Connection)

Enable Developer options and USB debugging

This varies slightly by Android version. In general, go to Settings, go to About phone, and tap on Build number 7 times. Then a Developer options menu will become visible in the Settings>System menu, in which you will be able to enable USB debugging. See the Android documentation for the most up-to-date instructions.

Connect Android device to WSL2 via TCP/IP

First, ensure that your device is available on the same network as your computer; this is achievable with a Wi-Fi connection.

Next, determine the IPv4 address that is assigned to your device. You can do this by navigating to the Settings>About phone menu on your device, and finding the IP address section.

Now, in your WSL2 terminal, run adb connect 192.168.0.22 , but be sure to replace 192.168.0.22with the IP address that is actually assigned to your device. The command will tell you that you’ve failed to authenticate to the IP address, but that’s because you still need to allow USB debugging on the device from WSL2.

Using the pop-up prompt on your device, check the option to “Always allow from this computer”, and tap the button that says Allow — this will grant WSL2 access.

Finally, confirm that you can debug Flutter apps with your device by typing flutter devices into your WSL2 terminal! You can now see your connected device listed!

Connect to Android device (Wired Connection)

Unfortunately, wired USB debugging is much more difficult to achieve on WSL2 running on Windows 10. Out of the box, WSL2 does not support connecting USB devices on Windows 10 — this behavior is only achieved through 3rd party open-source projects. So we won’t cover it in this article.

However, the good news is that WSL2 now supports connecting USB devices on Windows 11, thanks to contributions from these same 3rd party open-source projects.

Run a Flutter app on the Android Device

We’re still in WSL2. Create a Projects directory if it doesn’t already exist, and navigate to it.

mkdir -p $HOME/Projects && cd "$_"

Use the flutter create command to create a new project.

flutter create myapp;
cd myapp;

Run your new app!

flutter run

Nice work! We’re now using WSL2 to develop Flutter apps! In case you missed it, we previously explored how to use Android Virtual Devices for development and debugging, in case you don’t have a physical device…

--

--

Josh Kautz
Josh Kautz

Written by Josh Kautz

DevOps Software Engineer II at C.H. Robinson

No responses yet