Connecting to ADB Over Wi-Fi on Android 11+ and Windows

Connecting to ADB Over Wi-Fi on Android 11+ and Windows

30 November 2024 Stephan Petzl Leave a comment Tech-Help

Connecting your Android device to a Windows workstation over Wi-Fi using ADB (Android Debug Bridge) can enhance your workflow by eliminating the need for USB connections. However, users often face challenges when the Wi-Fi connection fluctuates, causing the port number to change. This guide will help you establish a more stable connection by addressing common issues and providing effective solutions.

Challenges with ADB Over Wi-Fi

When using ADB over Wi-Fi, every time your Android device reconnects to Wi-Fi, you might need to:

  • Enable wireless debugging in Android settings.
  • Note the dynamically assigned port number.
  • Reconnect using the adb connect command with the new port number.

Solutions for a Stable Connection

Fixing the Port Number

One effective method is to use a fixed port number. After connecting with the dynamic port, run:

adb tcpip 5555

This sets the port to 5555 until the device is rebooted. After a reboot, you’ll need to repeat the process. Here’s a script you can use to automate this:

adb connect [device_ip]:[dynamic_port]
adb tcpip 5555
adb disconnect
adb connect [device_ip]:5555

Replace [device_ip] and [dynamic_port] with your device’s IP address and the initial dynamic port number.

Automating the Connection Using Scripts

For users comfortable with scripting, you can automate the detection of the dynamic port and connection process using tools like nmap or network service discovery tools. Here’s a simple PowerShell snippet:

adb connect $IP`:$(nmap $IP -p 37000-44000 | Select-String tcp | ForEach-Object { $_.Split('/')[0] })

This script scans for open ports and connects to the device automatically.

Utilizing mDNS for Automatic Discovery

For a more seamless experience, enable mDNS discovery in ADB. This allows the device to be discovered automatically when wireless debugging is enabled. Use these commands to enable mDNS:

set ADB_MDNS_OPENSCREEN=1
adb kill-server
adb start-server 
adb mdns services

Once enabled, your device should appear in the list of discovered services, allowing for easy connection.

Enhancing Your Testing Workflow with Repeato

If you’re developing and testing Android applications, consider integrating Repeato into your workflow. Repeato is a no-code test automation tool for iOS and Android that simplifies the creation and maintenance of automated tests. By leveraging computer vision and AI, it ensures fast editing and execution of test scenarios. Repeato also supports ADB commands, enabling you to automate tasks like wireless ADB connections seamlessly, enhancing your productivity further.

For more advanced testing techniques and configurations, visit our documentation section.

Like this article? there’s more where that came from!