2016-06-21 200 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到您的類似問題。

相關問題