15

I have never had an issue debugging in Android until I switched to my current workspace. It happens in both Eclipse and IntelliJ. Previously I had an issue where the phone would hang at the "Waiting to attach debugger" dialog. Somehow I fixed that so the debugger at least attaches to my app.

Now I can set a breakpoint and have the debugger stop at that point. After about 5-10 seconds it disconnects no matter what I do. I'm able to read a few values of variables in memory before everything disappears. My co-worker is able to debug the same app just fine using Eclipse and we haven't been able to figure out what is wrong or different between our workstations (besides me using IntelliJ). We might have different images for our laptops though.

Any ideas? I've had to use Log statements for now but they are just too slow compared to using an actual debugger. I've tried using different USB cables and that didn't make much of a difference. I've gone through the debugger settings and nothing seemed out of the ordinary. Other Q/A's on SO have mentioned the app silently crashing, but I'm ruling that out due to it debugging fine for my co-worker.

telkins
  • 10,440
  • 8
  • 52
  • 79

5 Answers5

7

I've been having the same problem running IntelliJ IDEA build IC-133.193. I solved the problem with the following actions:

  1. Quit IntelliJ
  2. From a command line kill the adb server with adb kill-server
  3. From a command start the adb server as superuser with sudo adb start-server
  4. Restart IntelliJ

IntelliJ will start the adb server if it detects that it is not running. The key appears to be starting adb as superuser before starting IntelliJ.

[Update] This doesn't always work. The best solution I've found is to start the app on the device and then attach the debugger to the Android process through the Run menu. I haven't had any disconnections using this method.

neveu
  • 211
  • 2
  • 8
  • Thanks for the suggestion, I'll give it a shot. My problem was already dramatically reduced, not sure if I downloaded an update or something that improved it. My coworker suggests that the root cause could be due to a threading issue causing the debugger to become unsynchronized and then disconnected. – telkins Dec 04 '13 at 15:08
  • It turns out I still get disconnections even if I start adb as superuser. The best solution I've found so far is to start the app on the device and then attaching the debugger to the Android process from the Run menu. So far I haven't had any disconnects using this method. I'll edit the answer to reflect this. – neveu Dec 11 '13 at 17:40
  • I have this problem in Android Studio. I haven't experienced it while attaching to a running process. But sometimes the break points are reached on app start and so this isn't an option. – Jeff Lockhart Jul 20 '15 at 23:06
4

I have been fighting for a few days with adb not seeing my device. After trying many other posted solutions, I discovered that the issue was with Chrome also trying to connect its debugger to a web view. If Chrome is connected using chrome://inspect, then adb seems to disconnect. Quitting Chrome resolves the issue. Then I can connect with Android Studio and then restart Chrome and reconnect. Hope this helps someone else.

Chuck Krutsinger
  • 2,830
  • 4
  • 28
  • 50
  • 1
    I didn't see Chrome connected using chrome://inspect, but somehow, quitting Chrome fixed the problem, thanks! – auspicious99 Apr 17 '21 at 05:08
  • Yeah, I have been also fighting this problem :D But finally found out why. Thanks a lot! https://stackoverflow.com/a/69972782/4074312 – Orcun Sevsay Nov 25 '21 at 15:31
3

This fixed it for me

  1. Go to Power Options on your computer
  2. Click 'Change plan setting' on your chosen plan.
  3. Click 'Change advanced power setting' on your chosen plan.
  4. Expand 'USB Settings' .
  5. Expand 'USB selective suspend setting' and change it to disabled.
klsx
  • 441
  • 4
  • 6
0

This issue occurs to me when I try to use a USB 3.0 port. Using a USB 2.0 it does not happen.

gustavoknz
  • 482
  • 1
  • 6
  • 12
0

This happens to me when the cable connection is sensitive.

David
  • 2,782
  • 4
  • 31
  • 47