Android Studio Debugger Port Error - "handshake failed - connection prematurely closed"

When I try to attach the Android Studio Debugger to a process, I get the following error:

Error running Android Debugger (8603):
Unable to open debugger port (localhost:8603): java.io.IOException "handshake failed - connection prematurally closed"

Kudos to whoever spelled prematurely that way. Anyway, how do I get around this problem?

I'm using Android Studio 1.2.2 on Ubuntu. This did not help.


Solution 1:

The best and one solution for me was just to restart Android Studio.

Before I tried to restart adb server from command prompt or disable and enable adb integration from tools->Android->Check/Unchek the line, unplug and plug device , but nothing helped.

Solution 2:

For me these didnt work: Restart Android Studio,adb kill start server, restart phone.

Worked for me: Tools->Android->Disable and Enabled ADB Integration.

Solution 3:

On Windows, restarting Android Studio didn't work. I instead killed the "adb.exe" process then retried.

Solution 4:

I didn't need to restart my device, only restarting android studio fixed it ( clean your project if needed).

If doesn't work then restart your device.