如何调试从“adb shell am start -D”启动的android应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20205262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:27:32  来源:igfitidea点击:

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

androiddebuggingjdwp

提问by h3xStream

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 connectto the process using JDWP. I have try two different ways that both fail. (see following sections)

我需要调试一个已经安装在手机上的安卓应用程序。我可以在调试模式下启动应用程序,但无法使用 JDWP连接到进程。我尝试了两种不同的方法,但都失败了。(见以下部分)



Command line attempt

命令行尝试

1- Start the application

1-启动应用程序

[...]sdk\platform-tools>adb -d shell am start -D -n "package/package.SomeActivity"

The application starts and a alert display "/!\ Waiting for debugger".

应用程序启动并显示警告“/!\Waiting for debugger”。

2- Open a JDWP port

2- 打开 JDWP 端口

[...]sdk\platform-tools>adb forward tcp:8000 jdwp:7602

3- Attempt to connect using jdb

3- 尝试使用 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

IntelliJ 尝试

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.

我也用相同的警报启动了应用程序,但不幸的是 IDE 没有连接到远程进程。

Target device: 42f7cc14e2acbfab
Launching application: ********/********.SomeActivity.
DEVICE SHELL COMMAND: am start -D -n "********/********.SomeActivity"
Starting: Intent { cmp=********/********.SomeActivity }

Waiting for process: ********

采纳答案by h3xStream

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

已部署的应用程序配置为debuggable属性设置为 false。手机上的提示简直是误导。

回答by Vitaly Osipov

  1. Root the phone
  2. Open a root shell

    (computer)$ adb shell 
    (phone)$ su
    (phone)#
    
  3. Run amcommand

    # am start -D -n "package/package.SomeActivity"
    
  1. 将手机root
  2. 打开根外壳

    (computer)$ adb shell 
    (phone)$ su
    (phone)#
    
  3. 运行am命令

    # am start -D -n "package/package.SomeActivity"
    

This way you can debug any app, no matter if it has android:debuggableset or not.

这样您就可以调试任何应用程序,无论它是否已android:debuggable设置。