I haven\'t done Android development in a while, so my knowledge of modern Android development is spotty.
I\'m trying to learn React Native. I use WSL as my primary d
This answer by steelbrain from here worked for me:
Add the following to your WSL bashrc or zshrc:
export WSL_HOST_IP="$(tail -1 /etc/resolv.conf | cut -d' ' -f2)"
export ADB_SERVER_SOCKET=tcp:$WSL_HOST_IP:5037
Then create a firewall entry, create a new "Inbound" Rule. Select "Port" then Specific TCP port "5037" then "Allow the connection" then check all of Domain, Private and Public and add a name. After the firewall entry is added, open up its properties, go to Scope -> Remote IP Addresses -> Add "172.16.0.0/12".
Now that we're covered in the WSL2 VM and through the Firewall, you have to start the adb server with specific arguments to make it listen on all addresses (don't worry we've only whitelisted our WSL2 VM IP range so no security issues).
Create a vbs script, call it whatever and put this in it
CreateObject("WScript.Shell").Run "%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe kill-server", 0, True
CreateObject("WScript.Shell").Run "%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe -a -P 5037 nodaemon server", 0, True
Now all you have to do is invoke the vbs script once per reboot and your WSL VM will connect to your host ADB instance
(I just invoked those two commands in a regular CMD.exe shell:
%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe kill-server
%USERPROFILE%\AppData\Local\Android\Sdk\platform-tools\adb.exe -a -P 5037 nodaemon server
I guess he proposed vbs so it remains running, because if I were to put it in a .bat file the server would presumably die with the bat file, haven't tried)