How to debug an android application started from 'adb shell am start -D '?

醉酒当歌 提交于 2019-11-29 07:12:58

问题


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: ********

回答1:


  1. Root the phone
  2. Open a root shell

    (computer)$ adb shell 
    (phone)$ su
    (phone)#
    
  3. 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.




回答2:


The deployed application was configured with the debuggable attribute set to false. The prompt given on the mobile phone was simply misleading.



来源:https://stackoverflow.com/questions/20205262/how-to-debug-an-android-application-started-from-adb-shell-am-start-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!