2016-06-21 73 views
0

我一直试图运行jdb试图让它连接到我的android设备上的进程。是jdb给java.net.SocketException:连接重置

我试过的命令如下:

adb forward tcp:12345 jdwp:4127 

jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=12345 

我们可以假设具有PID 4127这个进程仍然活着。

然而,进入2个命令后,我收到了错误信息如下:

java.net.SocketException: Connection reset 

at java.net.SocketInputStream.read(SocketInputStream.java:209) 
at java.net.SocketInputStream.read(SocketInputStream.java:141) 
at com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:130) 
at com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:232) 
at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116) 
at com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:90) 
at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519) 
at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328) 
at com.sun.tools.example.debug.tty.Env.init(Env.java:63) 
at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066) 

我注意到一个奇怪的现象是,当我的应用程序1运行该输出只发生。这可能是由于程序运行时线程或进程或端口的冲突?

我可以得到下面的输出大部分的时候,我那个特定的应用程序被关闭:

Set uncaught java.lang.Throwable 
Set deferred uncaught java.lang.Throwable 
Initializing jdb ... 
> Input stream closed. 

我也尝试使用以下步骤运行在管理员模式下的命令提示符:

netsh advfirewall set global StatefulFTP disable 
adb forward tcp:12345 jdwp:4127 
jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=12345 

输出如下:

java.io.IOException: handshake failed - connection prematurally closed 
     at com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:136) 
     at com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:232) 
     at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116) 
     at com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:90) 
     at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519) 
     at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328) 
     at com.sun.tools.example.debug.tty.Env.init(Env.java:63) 
     at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066) 

Fatal error: 
Unable to attach to target VM. 

回答

0

问题在于我PROGR我正在启动一个android调试桥的实例。当我的程序试图运行jdb时,发生ADB竞态条件。由于我的程序在运行jdb之前已经创建了一个ADB实例,所以jdb将永远无法成功连接。即使通过命令提示符运行jdb也会得到相同的结果。关闭我的程序破坏了ADB的实例,这就是为什么我可以在程序关闭后通过命令提示符运行jdb。

我希望我的回答能够提供一些线索,为什么会出现这种现象。

0

尝试退出Android Studio。

问题是,Android Studio保持其ADB运行,这与您的冲突。有关更多详细信息,请参阅my answer到您的类似问题。

相关问题