I need to debug an android application that is already installed on a phone. I am able to start the application in debug mode but I can't connect to the process using JDWP. I have try two different ways that both fail. (see following sections)
Command line attempt
1- Start the application
[...]sdk\platform-tools>adb -d shell am start -D -n "package/package.SomeActivity"
The application starts and a alert display "/!\ Waiting for debugger".
2- Open a JDWP port
[...]sdk\platform-tools>adb forward tcp:8000 jdwp:7602
3- Attempt to connect using jdb
[...]sdk\platform-tools>jdb -attach 127.0.0.1:8000
java.io.IOException: shmemBase_attach failed:
at com.sun.tools.jdi.SharedMemoryTransportService.attach0(Native Method)
at com.sun.tools.jdi.SharedMemoryTransportService.attach(SharedMemoryTransportService.java:108)
at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116)
at com.sun.tools.jdi.SharedMemoryAttachingConnector.attach(SharedMemoryAttachingConnector.java:63)
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.
IntelliJ attempt
I have configure my local project to start the default Activity and uncheck the "Deploy application".
I also get the application started with the same alert but unfortunately the IDE doesn't connect to the remote process.
Target device: 42f7cc14e2acbfab
Launching application: ********/********.SomeActivity.
DEVICE SHELL COMMAND: am start -D -n "********/********.SomeActivity"
Starting: Intent { cmp=********/********.SomeActivity }
Waiting for process: ********
Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.
Open a root shell
(computer)$ adb shell
(phone)$ su
(phone)#
Run am
command
# am start -D -n "package/package.SomeActivity"
This way you can debug any app, no matter if it has android:debuggable
set or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With