Appium新手求助:adb devices无法识别已开USB调试的Android设备
Hey there, I’ve been exactly where you are when starting out with Appium—frustrated that my device won’t show up in adb devices even after enabling developer options and USB debugging. Let’s go through practical fixes that usually resolve this issue:
1. 确认USB连接模式
Make sure your Android device is set to File Transfer (MTP) or Media Device mode instead of just charging. Most devices let you switch this by pulling down the notification shade when connected to your computer and tapping the "Charging this device via USB" notification.
2. 安装对应品牌的USB驱动
Different Android manufacturers require their own USB drivers for adb to communicate with the device:
- For Samsung: Install Smart Switch (it includes the necessary drivers automatically)
- For Huawei/Xiaomi/OPPO/Vivo: Download the official USB driver from their respective support websites
- For Google Pixel: Use the Google USB Driver included in the Android SDK Platform Tools
3. 重启adb服务
Sometimes the adb daemon gets stuck. Run these commands in CMD or your terminal:
adb kill-server adb start-server
Then run adb devices again to check if your device appears.
4. 检查USB线和端口
Not all USB cables support data transfer—some are only for charging. Try swapping to a different USB cable (preferably the one that came with your device). Also, switch to a USB port on the back of your computer (front ports can sometimes have power or connectivity issues).
5. 重新验证USB调试权限
- Go back to your device’s Developer Options, toggle USB Debugging off, wait 10 seconds, then toggle it back on.
- When you reconnect the device to your computer, make sure to tap "Allow" on the pop-up that asks for USB debugging permission, and check the box for "Always allow from this computer" so you don’t have to do this every time.
6. 更新Android SDK Platform Tools
Outdated adb versions can cause compatibility issues. Update your Platform Tools to the latest version via Android Studio’s SDK Manager, or download the standalone package (no need for Studio if you don’t use it).
附:参考Node.js Appium代码片段
const { wdio } = require('webdriverio'); async function launchApp() { const driver = await wdio.remote({ path: '/wd/hub', port: 4723, capabilities: { platformName: 'Android', deviceName: 'YourDeviceID', // 后续可用adb devices获取到的设备ID替换 appPackage: 'com.your.app.package', appActivity: 'com.your.app.MainActivity', automationName: 'UiAutomator2' } }); // 这里可添加你的测试逻辑 console.log('App launched successfully'); await driver.deleteSession(); } launchApp().catch(err => console.error('Error:', err));
内容的提问来源于stack exchange,提问作者Gaurav Sharma

