Tracking and debugging Android source code in eclipse

Source: Internet
Author: User

Tian haili @ csdn

2012-9-29

 

This article explains how to import the android source code (including the framework and application code) in eclipse, and then track/debug the android Java code through a simulator or a real machine, unlike Android SDK-based pure application development, you can track and debug the code in the framework.

 

 

I. Preparations

 

Make sure that the following software environments have been installed and configured on the machine: JDK/Eclipse/Android SDK/ADT

That is, the environment required for Android Application Development under eclipse has been installed on the machine. If not, go to "build an Android Application Development Environment under Windows-Eclipse/Android/ADT".

 

In addition, to track and debug the android source code, you also need the android source code and the compilation environment of the source code, which can be:

  • Install Linux in a virtual machine environment, and compile the android source code in Linux. In this environment, if you want to debug in eclipse of the host machine, you also need to share the android source code path, which can be accessed by the host machine;
  • There is a separate android network environment that can be compiled to access the android source code path shared by the server on your client machine;
  • In Linux, you can use eclipse to track and debug the android source code on the local machine.

Note: No matter which method of work, the android source code must have been compiled, and the compiling adopts the Eng mode (vs user mode ). For how to compile Android platform and kernel, see compiling android2.2 platform under ubuntu10.10 and compiling android2.2 kernel under ubuntu10.10.

 

 

Ii. Basic settings

 

After the preparation is complete, make some basic settings.

 

1. Copy the. classpath file in the android source code path <android_root> to <android_root>;

2. Modify eclipse settings

Modify the eclipse. ini file and change the following content:

-Xms40m-Xmx384m

Changed:

-Xms128m-Xmx512m

Here, the minimum Java heap size is increased to 128 MB, and the maximum Java heap size is increased to 512 MB.

 

 

3. Create a project in eclipse

 

1. File> New> JAVA Project

2. Enter the project name.

3. Cancel use default location and enter or select the android source code path in location <android_root>

4. Select next> finish. There will be a long waiting process

The newly created project may have errors. add or delete the packages configured in the project according to the error prompt.

 

 

Iv. debugging environment Configuration

 

1. Right-click the project created in #3;

2. Select debug as> debug deployments ...;

3. Right-click "remote Java application" and select new. Alternatively, double-click "remote Java application" to create a new remote application.

4. Fill in name; select the project android2.3.7 you just created from the project; enter port 8700 (not necessarily 8700, go to the device view under ddms perspective to view the required port number ).

5. Save apply and exit.

 

 

V. debugging

 

It can be debugged through a simulator or a real machine.

Whether it is a simulator or a real machine:

  • Start the machine first (the simulator is started, or the real machine is turned on, and the PC is connected normally through USB). That is, the machine connection is displayed in the devices view of ddms perspective;
  • Make sure that the running code is the same as the code to be debugged.

 

Assume that we want to track the call of lock screen unlocking.

We know that the implementation of unlocking is in the lockscreen. Java ongrabbedstatechange () function and runs in the system_process process.

So,

1. Set a breakpoint for ongrabbedstatechange;

2. In device view, select system_process and click the crawler icon;

3. debug configuration created with section #4, debug;

4. When the unlock operation is performed on a simulator or a real machine, the Code stops at the breakpoint;

In this way, you can,

  • Place the cursor over a variable to check its value. You can also debug your code through various debugging methods in eclipse.
  • Use step into/step over/resume/suspend/terminate to control program execution in debug view.

 

 

Summary

This article can be used:

  • This article is based on the Windows environment, but not only applicable to the Windows environment, but also for Mac OS and Linux systems, but some paths and usage are different;
  • You can trace/debug the Java source code in Android (no matter the Framework Code or the Code in the app), and cannot debug C/C ++ code in the framework;
  • To enable the entire project to be compiled in eclipse,. classpath also contains the compiled content in out/. Therefore, you must ensure that the android source code has been compiled.
  • The premise of tracing/debugging is to set a breakpoint at the code to be debugged and know the process in which the code is executed.

Related Article

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.