Android Development
ADB
TCP/IP
Debugging
Mobile Technology

How can I connect to Android with ADB over TCP?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Android Debug Bridge (ADB) is a versatile command-line tool that allows developers to communicate with an Android device for debugging and other purposes. Typically, ADB operates through a USB connection, but it can be configured to connect over a TCP/IP connection. This connectivity method is particularly handy when USB debugging is inconvenient or impossible, such as when dealing with devices mounted in hard-to-reach places or needing to handle multiple devices simultaneously from a distance.

Prerequisites for ADB Over TCP

  1. Android Device: The device must be Android with developer options enabled.
  2. ADB Tools: Installed on your computer. ADB is part of the Android SDK platform-tools.
  3. Network Connectivity: Both the Android device and the PC must be on the same local network.

Steps to Connect ADB over TCP

Enabling Developer Options and USB Debugging

First, you need to activate developer options and USB debugging on your Android device:

  1. Go to Settings > About phone and tap on Build number 7 times to activate Developer Options.
  2. Return to Settings > System > Advanced > Developer options and enable USB debugging.

Setting up ADB over TCP/IP

To set up ADB over TCP/IP, follow these detailed steps:

  1. Connect the device to your computer via USB:
    • Ensure the device is connected to the same network as your computer.
  2. Open a command prompt or terminal on your computer:
    • Navigate to the directory where ADB is installed if it's not added to your system's PATH.
  3. Check connected devices:
    • Run adb devices to confirm your device is connected properly via USB.
  4. Switch ADB to TCP mode:
    • Execute the command:
bash
     adb tcpip <port>
  • Replace <port> with a port number, typically 5555.
  1. Disconnect the USB cable:
    • Remove the device from the USB connection.
  2. Connect over TCP/IP:
    • Find your Android device’s IP address in Settings > About phone > Status or Wi-Fi information.
    • Connect by executing:
bash
     adb connect <device-ip>:<port>
  • Replace <device-ip> with your device's IP address and <port> with the same port used earlier.
  1. Verify the Connection:
    • Run adb devices again. You should now see your device listed as connected via TCP/IP.

Troubleshooting Common Issues

Here are some common issues and their resolutions:

  • Device not found: Ensure both devices are on the same network and the correct IP address and port are being used.
  • Connection refused: Check if your Android device’s port is correctly set and listening. You might restart ADB in TCP mode and reconnect.
  • ADB not recognized: Ensure ADB is properly installed and your PATH environment variable includes the folder where ADB is installed.

Disconnection and Reverting to USB

To disconnect, simply use:

bash
adb disconnect <device-ip>:<port>

Reverting back to USB mode can be done by connecting the device via USB and running:

bash
adb usb

Summary Table

ActionCommand/LocationNotes
Enable USB DebuggingSettings > Developer optionsDeveloper options must be enabled first.
Start ADB over TCPadb tcpip <port><port> is usually 5555.
Connect to the Deviceadb connect <device-ip>:<port>Ensure the device and PC are on the same network.
Disconnectadb disconnect <device-ip>:<port>Useful to cleanly stop the TCP connection.
Revert to USBadb usbEnsures connection is set back to USB.

Conclusion

ADB over TCP/IP offers a flexible way to manage Android devices remotely, bypassing the need for a physical connection via USB. This can be exceptionally useful for developers testing apps on multiple devices simultaneously or when physical access to the device is limited. By following the steps and guidelines provided, setting up ADB over TCP should be straightforward, enhancing your development and debugging workflow.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.