android - 无法在 Android Studio 中附加调试器 - localhost :8600 java.net.ConnectException

标签 android debugging android-studio

在手机上运行调试时,我无法在 Android Studio 中附加调试器。

我目前使用的是运行 Android 4.4.4 的三星 S4(但在各种 Android 版本上尝试过 S5、S6、S7 和 Moto E 手机)。当我尝试运行它并出现以下任一错误时,它会超时:

I/System.out: Sending WAIT chunk
W/ActivityThread: Application is waiting for the debugger on port 8100...

或者

failed to open debugger port localhost:8600 java.net.ConnectException "connection refused"

应用程序说:

Waiting For Debugger
Application (process ) is waiting for the debugger to attach.
Force Close

Android Studio 版本:

Android Studio 2.2.2
Build #AI-145.3360264, built on October 18, 2016
JRE: 1.8.0_112-release-b05 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Mac 版本:

10.11.6 (15G1004)

我可以成功连接并运行应用程序,但是当我执行“运行”>“调试应用程序”>选择已连接的手机>“确定”时,我无法连接调试器。

我已经能够在使用相同手机的其他计算机(Windows 和 Mac)上以调试方式运行该应用程序。

经过数小时的调试和在线搜索,我尝试了各种方法:

  1. 使缓存失效/重启 Android 工作室

  2. 检查在端口 8100、8600、8601 等上运行的其他任何东西,当我从 bash 运行以下命令时没有任何返回:

    $ # while Android studio is trying to attach the debugger
    $ lsof -i :8100
    $ lsof -i :8600
    COMMAND  PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    

    工作室 6282 彼得 125u IPv4 0x973c7e31bda641ab 0t0 TCP 192.168.1.16:64022->ip-166-62-27-181.ip.secureserver.net:asterix (SYN_SENT) $ lsof -i :8601 $ $ # Android studio 附加调试器失败后 $ lsof -i :8100 $ lsof -i :8600 $ lsof -i :8601 $

  3. 运行工具 > Android > Android Device Monitor - 它显示了我的设备,但我在尝试调试应用程序时无法运行 Android Device Monitor,它说:“Monitor will be closed to enable ADB一体化。继续?”我在这里没有找到任何有用的东西。

  4. 搜索并杀死 adb 进程

    ps aux | egrep '(adb|java)'
    ... then doing `kill <pid>` or `kill -9 <pid>` if necessary for the found ones
    
  5. 重启安卓工作室

  6. 重启我的电脑

  7. 从 Oracle 网站更新 Java JDK — 但是,我不知道为什么 Android Studio 仍然说:“JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o”

  8. 完全卸载并重新安装 android studio - 例如,https://stackoverflow.com/a/18458893/376489 - 奇怪的是,我认为这适用于调试器的一次运行,然后又不行......

  9. 尝试运行 > 将调试器附加到 Android 进程 - 这没有帮助

  10. 试运行:

    ~/Library/Android/sdk/platform-tools/adb kill-server &&
     ~/Library/Android/sdk/platform-tools/adb start-server
    
  11. 尝试取消选中 Run > Edit Configurations > Run/Debug Configurations > Skip installation if APK has not changed

  12. 检查系统偏好设置 > 安全和隐私 > 防火墙 - 已关闭

  13. 更新 1:尝试撤销手机权限并重启手机

  14. 更新 1:静音 Android Studio 的所有断点

对于我在上面添加的细节中可能出现的问题或任何有意义的内容,还有其他想法吗?

最佳答案

很尴尬,但看起来好像前段时间我在/etc/hosts 文件中输入了一个 IP 地址来测试 localhost 的内容,但从未将其删除。我在另一篇帖子上发现了一条评论,说要检查您的/etc/hosts 中是否有以下内容:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

在注释掉那条虚假行后,调试器现在可以工作了。鉴于我在该文件中有十几个其他 IP(因此我可以更轻松地使用友好名称测试远程主机),我一定没有注意到底部的这个。我认为验证这是否是问题的一种更简单的方法是 ping localhost 并验证它是否解析为 127.0.0.1 的 IP 地址,例如,

$ ping localhost
PING localhost (127.0.0.1): 56 data bytes

这里的其他人也提出了很好的意见和建议,谢谢!

关于android - 无法在 Android Studio 中附加调试器 - localhost :8600 java.net.ConnectException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40823082/

相关文章:

android - 如何知道api版本和android源码

c# - 在 Microsoft Visual Studio 调试器中更改日期时间

android - 在事务中使用多个方法

Android Studio 配置 C++ 项目复选框

java - Eclipse 在没有断点的情况下暂停

android - Eclipse ADT : Working but "Terminate" button greyed out. ..?

java - Android Studio 中的舍入变量

android - 我在 Android Studio 中创建 Navigation Drawer Activity 后立即收到一条错误消息

flutter - 任务 ':app:signReleaseBundle' 执行失败

Android float 操作按钮打开小 View