title: How to debug an Android APK on a Genymotion emulator from a Linux command line?
body: <p>I am using a Genymotion (VirtualBox) Android emulator. When I'm trying to attach a JDB to a running Android app from a command line, I get a <code>java.io.IOException: handshake failed - connection prematurally closed</code> delight, namely:</p>
  
  <pre><code>$ 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&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  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&lt;link&gt;
          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.
  </code></pre>
  
  <p>Using the Android Studio IDE/GUI, however, I am able to attach a debugger with a click of the button. Can't debug with the Android Studio giving my situation.</p>