Android source code development tool-Java source code debugging (based on 4.1.2)

Source: Internet
Author: User
Debug Android Java source code

The back garden of the straw hat-Neo

Previously written: This article mainly focuses on debugging the Java source code. It should be said that it is the source code after system_process. This is a powerful tool for debugging and modifying the frameworks layer, but why is it still analyzed after system_process? If there is any result, I will update this article and try to debug the C ++ code, that is, the code in native, if this option is feasible, it will greatly reduce the number of our staff who focus on source code modification, which is much easier. It is not yet started. If it is feasible, I will release it as soon as possible. The method is not original, I just tested it successfully, so I will share it. Please indicate the source for reprinting. Thank you. (After testing, if the system compiled into the user version does not seem to be able to debug)

1. Configure the SDK Development Environment

I will not talk much about configuring the development environment. Due to working hours, I will add a tutorial on the development environment configuration in Windows and Linux. The working environment here is Windows XP, eclipse 4.2,

SDK details:

2. Import the android source code

The code I use here is Android 4.1.2 (mainly because my company is currently developing the tablet 4.1.2). I will focus on the source code of 4.1.2. The simulator will not be used for demonstration on the real machine, the principle is the same. Here, first of all, make sure that your source code can be compiled. There are a lot of tutorials for compiling source code on the internet, and I will make a self-understanding tutorial later.

2.1. Start eclipse

This is not detailed, so that you can click the icon directly. After startup:

2.2. Create a Java Project

Click file à New à javaproject in the upper left corner to create a Java project. First, I can compile the code. The root directory path is u: \ NEO \ android_4.1.2 \ 4.1.2.

The following interface is displayed.

2.3. Select the source code for Import

One thing we need to do before importing is to reduce the amount of source code imports. We can copy a file in the source code to the source code root directory. The path of this file is: (u: \ NEO \ android_4.1.2 \ 4.1.2 \ Development \ ide \ eclipse \. classpath). If you cannot see it, all the hidden files will be displayed ,:

Copy Past:

Now we need to select the source code to be imported, and the location is the source code path we want to import (here, note the root directory, the source code root directory ~~), Enter Project name: android4.1.2 and remove the use defalocation location check. Result:

Click next and the data will be imported. It may take about 10 minutes to import the data. Please wait.

Figure after import:

After finishing, it will be OK.

Project code:

3. Set the connection Port

In fact, it is through remote debugging, setting a socket port, the operation process

When you enter debugconfigurations, double-click Remote Java application to create a remote debugging and change the port number to 8600. (here, you need to enter the port number of the process you want to debug. Here I will attach a picture below, it can be explained that each process has a port number after it is started. To debug the process, you need to set the port number to enter. The following figure shows how to adjust settings, set the port number to 8604) and check the debug in the common column.

Click Apply.

4. Start the real machine or Simulator

Connect to a real machine or simulator. I only connect to the simulator. The real machine has been tested and is feasible.

First, create a new simulator (flat simulator). steps:

In window-> avdmanager, select new

Fill in the content. Note that the resolution is set to 1280x800, and the following abstractedlcd density must be set to 160 to display the tablet.

Click Create AVD. Start the simulator just created.

The simulator is already started.

5. set breakpoints

The startup of the simulator is slow. We set the breakpoint first. According to the startup process (you need to understand it), I added the breakpoint before starting all the services, the breakpoint is set in frameworks/base/services/Java/COM/Android/Server/systemserver. the second line of Java, that is, the first sentence when running () is started. The subsequent code is used to start various services.

After the breakpoint is set, connect to the simulator.

6. Start debugging.

The next step is debugging. During the startup process, we can see in ddms that the device is offline at the beginning, and when the device is online, we start the configured debug.

After you click debug, you will see a bug sticking to the system_process process. This shows that debugging is ready.

A moment later, we will enter the breakpoint we just set.

This is the result. You can also view the value of the variable and modify the value in the memory for debugging. (In fact, to be honest, the explanatory language is better for debugging, the compilation type is good, and the memory value can be modified ).

The debugging process is like this. I only made a small demonstration here. I believe that there is more than enough to talk about it. As a beginner, I cannot write too much details. If you have any omissions, please forgive me. In fact, we can see part of the system startup process through this. You can call launcher, setting, and other things in frameworks. If you have any good methods, please share them 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.