简体   繁体   English

如何从 Linux 命令行在 Genymotion 模拟器上调试 Android APK?

[英]How to debug an Android APK on a Genymotion emulator from a Linux command line?

I am using a Genymotion (VirtualBox) Android emulator.我正在使用 Genymotion (VirtualBox) Android 模拟器。 When I'm trying to attach a JDB to a running Android app from a command line, I get a java.io.IOException: handshake failed - connection prematurally closed delight, namely:当我尝试从命令行将 JDB 附加到正在运行的 Android 应用程序时,我得到一个java.io.IOException: handshake failed - connection prematurally closed delight,即:

$ adb jdwp
...
1720
1744
^C
$ adb forward tcp:1234 jdwp:1744
$ adb forward --list
192.168.56.105:5555 tcp:1234 jdwp:1744

$ ss -t -a | grep 1234
LISTEN 0      128        127.0.0.1:1234           0.0.0.0:*           

$ ifconfig
...
vboxnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.1  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::800:27ff:fe00:0  prefixlen 64  scopeid 0x20<link>
        ether 0a:00:27:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 243  bytes 48382 (47.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ jdb -attach localhost:1234
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
java.io.IOException: handshake failed - connection prematurally closed
        at jdk.jdi/com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:142)
        at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:255)
        at jdk.jdi/com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:119)
        at jdk.jdi/com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:83)
        at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
        at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
        at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
        at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1095)

Fatal error:
Unable to attach to target VM.

Using the Android Studio IDE/GUI, however, I am able to attach a debugger with a click of the button.但是,使用 Android Studio IDE/GUI,我可以通过单击按钮来附加调试器。 Can't debug with the Android Studio giving my situation.无法使用给出我的情况的 Android Studio 进行调试。

It appears that it's the Android Studio itself causing this problem... Also killing the adb server with the Android Studio running, makes the adb server to automatically restart.看来是 Android Studio 本身导致了这个问题...同时在运行 Android Studio 的情况下终止 adb 服务器,使 adb 服务器自动重启。 The solution here is not to run the Android Studio doing a JDB session from the command line.这里的解决方案不是运行 Android Studio 从命令行执行 JDB session。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM