You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio 3.4.1无法连接ADB,新安装后运行应用报错求助

Hey, I’ve dealt with this exact ADB connection headache before when using Android Studio 3.4.1. Let’s walk through some reliable fixes to get your sample app running on your device:

1. Double-Check Your Localhost Configuration

The error specifically calls out localhost, so let’s start here:

  • Open your system’s hosts file:
    • Windows: Navigate to C:\Windows\System32\drivers\etc\hosts (you’ll need admin rights to edit this—right-click your text editor and select "Run as administrator" first)
    • macOS/Linux: Open Terminal and run sudo nano /etc/hosts
  • Make sure these two lines are present (add them if they’re missing):
    127.0.0.1       localhost
    ::1             localhost
    
  • Save the file and close your editor.
2. Restart the ADB Server

This is the quickest fix for most ADB glitches:

  • Go to the Terminal tab at the bottom of Android Studio
  • Run these two commands one after another:
    adb kill-server
    adb start-server
    
  • Alternatively, you can use the Studio toolbar: Go to Tools > Android > Enable ADB Integration, uncheck the box, wait a second, then check it again. This triggers a server restart too.
3. Fix Port Conflicts

ADB uses port 5037 by default, and other programs (like some emulators or antivirus tools) might hog it:

  • Windows: Open Command Prompt and run netstat -ano | findstr :5037. Note the PID number, then open Task Manager, find that PID, and end the process.
  • macOS/Linux: In Terminal, run lsof -i :5037 to find the process using the port, then kill it with kill -9 <PID> (replace <PID> with the number you found).
  • Restart the ADB server again (step 2) after killing the conflicting process.
4. Verify Your Device’s Connection Settings

Sometimes the issue is on the device side:

  • Make sure USB Debugging is enabled on your Android device: Go to Settings > About Phone, tap "Build Number" 7 times to unlock Developer Options, then go back to Settings > Developer Options and toggle on "USB Debugging".
  • Unplug your USB cable, wait 5 seconds, then plug it back in. Check if Android Studio recognizes your device in the dropdown menu next to the Run button.
  • If you’re using wireless debugging (optional), ensure your device and computer are on the same Wi-Fi network, then connect via adb connect <device-ip-address> (you’ll find your device’s IP in Settings > About Phone > Status).
5. Update Your SDK Tools

Outdated platform tools can cause ADB issues:

  • Open Android Studio and go to File > Settings > Appearance & Behavior > System Settings > Android SDK
  • Switch to the SDK Tools tab, check for updates to Android SDK Platform-Tools (this is where ADB lives), and install any available updates.
  • Restart Android Studio after updating.
6. Reset Android Studio Settings (Last Resort)

If nothing else works, resetting Studio’s config can clear hidden bugs:

  • Close Android Studio completely
  • Delete the configuration folder:
    • Windows: C:\Users\<YourUsername>\.AndroidStudio3.4
    • macOS: ~/Library/Preferences/AndroidStudio3.4
    • Linux: ~/.AndroidStudio3.4
  • Reopen Android Studio, import your project, and try running the app again.

内容的提问来源于stack exchange,提问作者Mujas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:14:30