Android Source Code development tool--java source debugging (based on 4.1.2)

Source: Internet
Author: User

Original address: http://blog.csdn.net/jinzhuojun/article/details/8868038 debugging Android Java source code

The back garden of the straw hat--neo

Written in the previous words: Here is mainly to debug Java source code, should be said to be in the system_process after the source, which for debugging and modification frameworks layer of people is really a weapon, but as for why in the system_process, I still in analysis, If there is a result I will update this article, and is trying to debug C + + code, is the code in native, if this is feasible that will greatly reduce us to modify the source of the main staff is much easier, has not yet begun, if feasible I will publish as soon as possible, the method is not original, just I successfully tested , so share. Reprint please indicate the source, thank you. ( after testing, if the system compiles into the user version, it does not seem to debug )


1. Configuring the SDK development environment

This is about configuring the development environment I don't have to say, because of working time, I will add a tutorial on the development environment configuration under Windows and Linux. The working environment here is Windows Xp,eclipse 4.2,

SDK conditions such as:

2. Import Android Source code

I use the code here is the Android 4.1.2 (mainly at present my company temporarily in the development of 4.1.2 's tablet), I will 4.1.2 Source-based, simulator demo, the real machine will not demonstrate, the principle is the same. Here, first to ensure that one thing is your source code to be able to compile the line, compiling the source of the tutorial online there are many, I will also do a copy of their own understanding of the tutorial.

2.1. Start Eclipse

This is not detailed, lest wordy, direct dot icon. After startup:

2.2. New Java Project

Click Fileànewàjavaproject in the upper left corner to create a new Java project. First of all, my code can be compiled before, and the root directory path is: U:\neo\android_4.1.2\4.1.2.

And then you go to the following interface

2.3. Select the imported source code

Before the import we need to do a thing, is to reduce the amount of source import, we can copy a file in the source code to the root directory, the path of the file is: (U:\neo\android_4.1.2\4.1.2\development\ide\eclipse \.classpath), if you don't see it, show all the hidden files:

Copy Past:

Now we need to choose the source to import, location for the source code we want to import (note here is the root directory oh, source root directory ~ ~), enter project name:android4.1.2, remove use defaultlocation tick, results:

Then click Next, will be imported, the import takes about more than 10 minutes, wait, hehe.

After the import has completed the diagram:

After finish, it's OK.

Project Code:

3. Set the port for the connection

In fact, by remote to debug, set a socket port, the operation process

When entering debugconfigurations, double-click Remote Java Application and change the port number to 8600 (what you need to do here is enter the port number of the process you want to debug, here I enclose a picture in the back to explain, After each process start has a port number, to debug you need to set the port number to enter, after the figure, for example, to tune settings, then the port number is set to 8604, and the common bar in the debug hook.

Click Apply.

4. Start the real machine or simulator

Connected to the real machine or simulator, I only connect the simulator, the real machine has been tested, is feasible.

To start with a new simulator (tablet simulator), step:

In Window->avdmanager, select New

Fill in the content, here to note: Resolution set to 1280x800, the following abstractedlcd density to be set to 160, so that the display is flat.

Click Create AVD. Start the simulator you just created.

The simulator is already starting

5. Set Breakpoints

The simulator starts relatively slowly, we set the breakpoint first, according to the start-up process (this needs to understand), I added a breakpoint before all services started, breakpoints set in frameworks/base/services/java/com/android/server/ The No. 775 line of Systemserver.java, the first sentence that starts at run (), is followed by the code to start the various services.

After setting the breakpoint, start the connection simulator.

6. Start debugging

The next step is to debug, start the process we can see in the DDMS, the device is just beginning to be offline, and so on when the device is online, we start the debug just set.

After debugging, you will see a small bug stuck in the system_process process, which indicates that you can debug.

Wait a moment and you'll get to the breakpoint we just set.

The effect is this, the steps to debug this is not much to say, you can also see the value of the variable here, as well as modify the memory value in order to debug. (In fact, explain the type of language better debugging, compile-type is not cool, at least can modify the value of the memory).

debugging process is so, here only to do a small demonstration, I believe that many do not have to say, as it novice I can not write too detailed, if there are omissions please forgive me. In fact, through this also see the system part of the start-up process, you can adjust launcher, setting and other frameworks below the east, if you have a good way please share with each other, thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.