Keywords: ADB Restart | Android Studio | Device Connection Issues | Command Line Tools | Troubleshooting
Abstract: This article provides a comprehensive exploration of manual ADB restart methods in Android Studio, with detailed analysis of the ADB client-server architecture. When Android devices suddenly become unrecognizable by Android Studio, executing adb kill-server and adb start-server commands via command line effectively resolves the issue. The article thoroughly explains ADB's three core components (client, daemon, and server) and provides specific operational steps for Windows systems. It also covers ADB port management, device connection status detection, and troubleshooting methods for common connection failures, offering complete ADB troubleshooting solutions for Android developers.
ADB Architecture and Working Principles
Android Debug Bridge (ADB) is a powerful command-line tool that employs a client-server architecture to facilitate communication between development machines and Android devices. This architecture consists of three key components: the client responsible for sending commands, typically running on the developer's computer; the daemon (adbd) executing commands on the device as a background process; and the server managing communication connections between clients and daemons.
When a developer initiates an ADB client, the system first checks whether an ADB server process is already running. If none exists, the client automatically starts the server process. Upon startup, the server binds to local TCP port 5037 and listens for command requests from all ADB clients. Subsequently, the server scans odd-numbered ports in the range 5555 to 5585 to discover running emulators and establishes connections for each discovered ADB daemon.
Root Causes of Device Connection Issues
In practical development scenarios, situations frequently arise where devices suddenly become unrecognizable by Android Studio. This phenomenon typically stems from abnormal states of the ADB server process. When developers disconnect and reconnect USB devices, the ADB server may fail to properly update device connection status, resulting in connected devices no longer appearing in the device list.
The ADB server, as the core component of connection management, maintains status information for all connected devices. If the server process experiences memory leaks, resource contention, or state inconsistencies, device recognition failures may occur. In such cases, even re-enabling ADB integration through Android Studio's "Tools->Android->Enable ADB Integration" option may not resolve the problem.
Manual ADB Restart Solution
To address the aforementioned issues, the most effective solution involves manually restarting the ADB server through command line. Specific operational steps are as follows:
- Open Command Prompt (Windows system) or Terminal (macOS/Linux systems)
- Navigate to the Android SDK's platform-tools directory:
cd path_to_android_sdk/platform-tools - Terminate the currently running ADB server:
adb kill-server - Restart the ADB server:
adb start-server
The following code example demonstrates the complete operational workflow:
# Change to platform-tools directory
cd C:\Users\username\AppData\Local\Android\Sdk\platform-tools
# Terminate ADB server process
adb kill-server
# Restart ADB server
adb start-server
# Verify device connection status
adb devices
ADB Server Management Mechanism
The ADB server operates in singleton mode, meaning only one server process can be active at any given time. The adb kill-server command forcibly terminates the currently running server process, releasing all occupied system resources. When executing adb start-server, the system reinitializes the server state, establishes new port listening, and rescans all available device connections.
This restart mechanism resembles the "service restart" operation in network services, capable of clearing potential state inconsistencies within the server. In Windows systems, the ADB server typically runs as a background service, and restart operations do not affect the normal operation of other system processes.
Device Connection Status Verification
After restarting the ADB server, developers need to verify whether devices are correctly recognized. The adb devices command lists all connected devices and emulators. Normal output should display device serial numbers and connection status:
List of devices attached
emulator-5554 device
0a388e93 device
The "device" status indicates successful connection to the ADB server. If devices still do not appear in the list, it may be necessary to check whether USB debugging is enabled, ensure stable USB cable connections, or try different USB ports.
Port Management and Conflict Resolution
ADB uses specific port ranges for communication. Emulators employ consecutive port pairs: even-numbered ports for console connections and odd-numbered ports for ADB connections. For example, the first emulator uses 5554 (console) and 5555 (ADB), the second uses 5556 and 5557, and so forth.
When port conflicts occur, the ADB server may fail to start normally. In such cases, port occupancy can be checked using the following commands:
# Windows systems
netstat -ano | findstr :5037
# macOS/Linux systems
lsof -i :5037
If port 5037 is occupied by other processes, the occupying processes must be terminated before restarting the ADB server.
Advanced Troubleshooting Techniques
Beyond basic server restarts, more in-depth troubleshooting methods can be employed:
- Force USB Connection Reset: Disable and re-enable Android USB devices in Device Manager
- Clear ADB Keys: Delete adbkey files in the
%USERPROFILE%\.androiddirectory - Check Firewall Settings: Ensure firewalls are not blocking communication on ADB-related ports
- Update Drivers: Install the latest Android USB drivers
Wireless Debugging Connection Management
For devices supporting wireless debugging, ADB connection issues may involve network configuration factors. Wireless debugging requires both development machines and devices to connect to the same Wi-Fi network and complete pairing processes. If wireless connections encounter problems, the following steps can be attempted:
# Switch to TCP/IP mode
adb tcpip 5555
# Connect to device IP address
adb connect device_ip_address:5555
# If connection fails, restart ADB server
adb kill-server
adb start-server
Preventive Maintenance Recommendations
To avoid frequent ADB connection issues, developers are advised to adopt the following preventive measures:
- Regularly update Android SDK Platform Tools to the latest version
- Ensure all debugging operations are completed before disconnecting devices
- Avoid running multiple ADB client instances simultaneously
- Regularly clean temporary files and cache data
- Use high-quality USB cables and interfaces
By understanding ADB working principles and mastering proper troubleshooting methods, developers can effectively resolve device connection issues and improve Android application development efficiency. Although manually restarting the ADB server is a simple operation, it often plays a crucial role in solving complex connection failures.