简体   繁体   English

如何调试Android平台的Java文件?

[英]How can I debug Android platform java files?

I'm interested in learning more about certain Android services (ie: ActivityManager, PackageManager, etc). 我有兴趣进一步了解某些Android服务(例如:ActivityManager,PackageManager等)。 So, I would like to follow their (java code only for now) execution, place breakpoints, etc. Is this possible either on the emulator or on a target device? 因此,我想遵循它们的执行(仅Java代码),放置断点等。这可能在模拟器上还是在目标设备上?

Edit: for instance, some PackageManager (AOSP code) is at services/java/com/android/ server/pm/PackageManagerService.java. 编辑:例如,某些PackageManager(AOSP代码)位于services / java / com / android / server / pm / PackageManagerService.java。 I realize this ultimately becomes a thread of system_server. 我意识到这最终成为system_server的线程。

I have root (in both emulator and on my physical phone) and I think that I should be able to build these services from AOSP source. 我有root用户(在模拟器和物理电话中都有),我认为我应该能够从AOSP源构建这些服务。

I'm happy to work via logs (logfiles, logcat, etc) or via actual debugging tools (gdb, eclipse, etc). 我很高兴通过日志(日志文件,logcat等)或通过实际的调试工具(gdb,eclipse等)进行工作。 What works best? 什么最有效? Should I just add log messages to everything or can I somehow hook up an IDE on my PC so I can drill down into elements, look at the stack, etc? 我应该只向所有内容添加日志消息,还是可以以某种方式在PC上连接IDE,以便深入研究元素,查看堆栈等?

most phone not build from AOSP, and can replace the parts with AOSP built ones. 大多数电话不是使用AOSP构建的,而是可以使用AOSP内置的部件来替换这些部件。 so to use emulator is better. 所以使用模拟器更好。

  1. first important thing, make sure your are running corresponding system and source. 首先,请确保您正在运行相应的系统和源。 I think the official system image for emulator is OK, just checkout the right git tag from AOSP 我认为模拟器的官方系统映像可以,只需从AOSP中检出正确的git标签即可
  2. make a normal Java project in Eclipse, add the sources you want to trace to that project. 在Eclipse中创建一个普通的Java项目,然后将要跟踪的源添加到该项目中。 this project need not build-able, but the packages and classes need be parsed right by Eclipse. 这个项目不是可构建的,但是包和类需要由Eclipse正确解析。
  3. run your emulator, start the DDMS, find process you want to debug, mark it as debug-able with DDMS, it will show a spider and port number on that process 运行仿真器,启动DDMS,找到要调试的进程,并使用DDMS将其标记为可调试,它将在该进程上显示一个蜘蛛号和端口号
  4. setup a java remote debug configuration in Eclipse, connecting to the port number in step 3 在Eclipse中设置Java远程调试配置,并在步骤3中连接到端口号
  5. you got there, add breakpoints and enjoy. 您到达那里,添加断点并享受。

Good Luck. 祝好运。 it is a Big Work for you :) 这对您来说是一项艰巨的工作:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM