我需要调试一个已经安装在手机上的android应用程序。我可以在调试模式下启动应用程序,但无法使用jdwp连接到进程。我试过两种不同的方法都失败了。(见以下章节)
命令行尝试
1-启动应用程序
[...]sdk\platform-tools>adb -d shell am start -D -n "package/package.SomeActivity"
应用程序启动并显示警告“/!\正在等待调试器”。
2-打开JDWP端口
[...]sdk\platform-tools>adb forward tcp:8000 jdwp:7602
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.
智能尝试
我已将本地项目配置为启动默认活动并取消选中“部署应用程序”。
我还使用相同的警报启动应用程序,但不幸的是,IDE没有连接到远程进程。
Target device: 42f7cc14e2acbfab
Launching application: ********/********.SomeActivity.
DEVICE SHELL COMMAND: am start -D -n "********/********.SomeActivity"
Starting: Intent { cmp=********/********.SomeActivity }
Waiting for process: ********
最佳答案
根电话
打开根壳
(computer)$ adb shell
(phone)$ su
(phone)#
运行
am
命令# am start -D -n "package/package.SomeActivity"
这样,您就可以调试任何应用程序,不管它是否设置了
android:debuggable
。