“Failed to attach to the remote VM” connecting jdb to the android emulator on Windows

后端 未结 4 1727
粉色の甜心
粉色の甜心 2020-12-29 10:26

I’ve been trying to connect jdb to the android emulator for a little while, and have been met repeatedly with:

jdb -sourcepath ./src -attach localhost:8700

java.         


        
相关标签:
4条回答
  • 2020-12-29 10:46

    Currently this is working for me -- making a socket rather than a shared memory connection.

    >jdb –sourcepath .\src -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8700

    Beforehand you need to do some setup -- for example, see this set of useful details on setting up a non-eclipse debugger. It includes a good tip for setting your initial breakpoint -- create or edit a jdb.ini file in your home directory, with content like:

    stop at com.mine.of.package.some.AClassIn:14

    and they'll get loaded and deferred until connection.

    edit: forgot to reference Herong Yang's page.

    0 讨论(0)
  • 2020-12-29 10:50

    Try quitting Android Studio.

    I had a similar problem on the Mac due to the ADB daemon already running. Once you quit any running daemons, you should see output similar to the following:

    $ adb -d jdwp
    28462
    1939
    ^C
    $ adb -d forward tcp:7777 jdwp:1939
    $ jdb -attach localhost:7777 -sourcepath ./src
    Set uncaught java.lang.Throwable
    Set deferred uncaught java.lang.Throwable
    Initializing jdb ...
    > 
    

    See my other answer to a similar question for more details and how to start/stop the daemon.

    0 讨论(0)
  • 2020-12-29 11:02

    In order to debug application follow this steps:

    Open the application on the device.

    Find the PID with jdwp (make sure that 'android:debuggable' is set to true in the manifest):

    adb jdwp
    

    Start JVM with the following parameters:

    java -agentlib:jdwp=transport=dt_shmem,server=y,address=<port> <class>
    

    Expected output for this command:

    Listening for transport dt_shmem at address: <port>
    

    Use jdb to attach the application:

    jdb -attach <port>
    

    If jdb successful attached we will see the jdb cli.

    Example:

    > adb jdwp
      12300
    > java -agentlib:jdwp=transport=dt_shmem,server=y,address=8700 com.app.app
      Listening for transport dt_shmem at address: 8700
    > jdb -attach 8700
      main[1]
    
    0 讨论(0)
  • 2020-12-29 11:03

    Answer #1: Map localhost in your hosts file, as I linked to earlier. Just to be sure.

    Answer #2: If you're using shared memory, bit-size could easily become an issue. Make sure you're using the same word width everywhere.

    0 讨论(0)
提交回复
热议问题