简体   繁体   中英

How can I debug Android platform java files?

I'm interested in learning more about certain Android services (ie: ActivityManager, PackageManager, etc). 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?

Edit: for instance, some PackageManager (AOSP code) is at services/java/com/android/ server/pm/PackageManagerService.java. I realize this ultimately becomes a thread of 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.

I'm happy to work via logs (logfiles, logcat, etc) or via actual debugging tools (gdb, eclipse, etc). 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?

most phone not build from AOSP, and can replace the parts with AOSP built ones. 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
  2. make a normal Java project in Eclipse, add the sources you want to trace to that project. this project need not build-able, but the packages and classes need be parsed right by 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
  4. setup a java remote debug configuration in Eclipse, connecting to the port number in step 3
  5. you got there, add breakpoints and enjoy.

Good Luck. it is a Big Work for you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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