Could not open debug port: java.net.SocketException "Socket closed"

I get this error when trying to debug an Android application on Android Studio (v.0.4.4):

Error running <appname> [assembleDebug]: Unable to open debugger port : java.net.SocketException "Socket closed" 

The application is compiled and can be transferred to the phone using adb. No problem with adb; I can install / control logcat etc. I can load another project and debug it just fine. I come back to this and it is still broken. Thus, to eliminate the problem with the PC (actually Linux vm works under windows), install Android Studio, etc. I rebooted this vm and host.

I had this problem last year and I “fixed it” and then uninstalling Eclipse (I suspected that maybe he was trying to get the same socket).

I spent some time searching on Google and trying, but they have no meaning.

The problem arose around the time I released a signed, augmented release build. Until then, I was just running a debug build. However, I believe that all I did to create this version of the assembly was to edit build.gradle and configure Android Studio to automatically subscribe apks. I have since reverted the changes to build.gradle, but the problem remains.

I do not see the corresponding errors in any Android Studio log files; as if this exception is being captured, reported on the screen, but not registered anywhere.

Hopefully someone who reads this can suggest a few things to change this that I missed.

+47
intellij-idea android-studio
Feb 13 '14 at 21:48
source share
10 answers

On the Android Studio desktop, click the "Select button" Run / debug configuration "button (one with the Android icon), you can choose the correct option.

+44
Feb 17 '14 at 11:37
source share

I had a "Socket closed" error for several weeks, and this confused me. Today I found that although starting with the debug icon still gives me "Socket closed", if I attach the debugger later, it works (in the screenshot). I hope this saves someone else’s time.

Screenshot highlighting the attach debugger icon

+30
Jul 01 '14 at
source share

I was able to fix this problem by selecting the application configuration. In the screen above, the screenshot to the left of the start button allows you to choose a configuration. Choose one without brackets.

+25
01 Oct '14 at 15:51
source share

To avoid this problem and actually run from Android Studio, I had to explicitly switch the build option I was working in (through the panel that appears when selecting “build options” on the left edge). Then, when actually pressing the debug button up for my Android app setup (selected from the drop-down menu to the left of the Run / Debug icons), it will correctly deploy the build option mode I was in. (It would be nice if I could configure various configurations of Android applications to expand different types of assemblies from the drop-down menu, instead of switching options more manually, but I don’t see how now.

enter image description here

Also in the buildTypes section of the build.gradle file, you probably want debuggable true , otherwise your process will not appear in the dialog box if you try to manually connect the debugger.

+3
09 Oct '14 at 19:31
source share

I was getting this error on Linux, and the problem is that another previous process took the port and hung it. Thus, the solution is netstat to find a process blocking a port, then kill that process or restart the computer.

+3
Nov 07 '16 at 10:55
source share

I came across the same behavior, the above solutions did not work for me, but I have a tiny argument: my application extends android .app.Application. What I found for me is to edit the run / debug configuration ("Edit configurations ...") and select "Do not run action" instead of "Run default action".

+2
May 23 '15 at 14:54
source share

I ran into this problem just now, a simple solution: if you have multiple instances running, make sure that a different JMX port is specified in your startup script. refer to image

+2
Aug 29 '17 at 10:28
source share

I was getting this error because I had the "Test Kind" option in the "Run / Debug Configurations" dialog box set to "All in Package" and not "Test Class". When I set it to "Test Class", the debugger worked flawlessly.

enter image description here

+1
03 Oct '17 at 2:04 on
source share

I had a similar problem with a Java program. I restarted the IDE and changed the JMX port number. Then the program started in debug mode without any problems.

+1
Nov 08 '17 at 12:00
source share

Make sure your Android phone is well connected.

-2
Mar 07 '17 at 20:40
source share



All Articles