JDB doesn't work when attaching to a running Android process

Viewed 17

I want to attach debugger to running android application on a physical device connected through USB. The device is rooted using magisk. The ro.debuggable property also set to 1 using resetprop to make all apps debuggable.

For example, the app will be calculator (com.android.calculator2).

The exact steps I did:

  1. adb kill-server Make sure to restart the adb server.

  2. adb devices Start the server again and make sure the device is authorized.

  3. Run the app (calculator in my example).

  4. adb shell ps | grep calculator Find the app ID.

    u0_a88        4445 16282 4193244 133532 0                   0 S com.android.calculator2
    

    The app ID is 4445.

  5. adb jdwp | grep 4445 Make sure the app id is in the debuggable applications list. Output: 4445. So the app is debuggable.

  6. adb forward tcp:7777 jdwp:4445 Forward 7777 local tcp port to jdwp.

  7. jdb -attach localhost:7777 Connect JDB to the port.

And here is the problem. At the last step nothing happens. JDB doesn't exit nor connect, also it doesn't output anything on any input command.

I also tried Android Studio. I tried two options. Manually add configuration to connect to remote JVM and use Attach Debugger to Android Process option. The first option (connect to remote JVM configuration) doesn't work. I used this command line flags: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:7777. Port forwarding is done the same way. Android Studio as well does not connect nor exit or print error. Just nothing.

But the Attach Debugger to Android Process option works great. It successfully connects to the app and I can debug it and set breakpoints as expected.

I also want to mention that I used am set-debug-app command before to make the app wait for the debugger to connect before start. When either jdb from command line or Android Studio remote connect to JVM option is used, the app doesn't resume, so it seems like Android doesn't see the debugger at all. But when I connect the debugger via Attach Debugger to Android Process, the app resumes after attaching the debugger as expected.

Why JDB does not attach to the app while Android Studio does via option Attach Debugger to Android Process? What I do wrong?

0 Answers
Related