The Tools

Throughout the development lifecycle of writing, building, and running the application, the primary tools Android developers use are:

Eclipse Java Editor

A specific text editor for Java that Android SDK has informed about the Android programming environment. The editor not only warns you about code the compiler can't parse, but also gives you a wealth of information about what it can.

Java and Dalvik Build System

Recall that Android converts your Java application to run on the Dalvik virtual machine under Android. The Java compiler and the Dalvik translator both provide error information if they can't build your application. Eclipse Debugger

Eclipse provides a source-level debugger that the Android SDK connects with the running Dalvik bytecode, so you have all the debug capability you'd normally expect from a Java program running under Eclipse.

Logcat

Android also provides a general-purpose logging package that you can take advantage of to log informational or error messages from your running application. Perhaps of more importance, Android uses this facility extensively to tell you what is going on as it starts up, initiates your application, and tries to run it. There is also a special logcat log for telephony-related messages.

[J] DebugTest.java

[J] DebugTest.java

import android.app.Activity;

6 public class Defcugrest extends Activity {

/** Called wnen tne activity is first created. */ 8© ^Override public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState) ; setContentView (R. layout .rr.ain) ;

12 13

public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState) ; setContentView (R. layout .rr.ain) ;

12 13

Figure 5-1. Eclipse debug window upon startup

Android Debug Bridge (adb)

This provides a command-line debugging interface to a running Android phone or emulator.

DDMS

Android also provides a special window-oriented debugging environment custom tailored for Android and the Dalvik VM. Traceview

An Android-specific utility that tracks all the method calls your application executed and the time spent in each method.

The Android SDK takes full advantage of the features built into the Eclipse IDE, including those in the Eclipse text editor, which is customized for Java source code development. Let's use a simple application as an example of some of that editor's features. If you're already an expert on using Eclipse for Java development, you can skip this section. If you're new to Eclipse (or new to Java), there are some hints here that will speed up your development of Android applications.

We've created a new Android project called DebugTest, using Eclipse and the Android SDK (File ^ New ^ Project ^ Android Project). When you do that, and open the Java source file the SDK created for you, you get a central pane that looks like Figure 5-1. This is the Eclipse Java text editor, and it is already doing its job to point out errors in the nascent application.

In this case, the error indication is in the left margin: the little lightbulb and red X on line 11. Within that line, the editor has underlined the R in R.layout.main to tell you specifically where there's a problem. Editors in Eclipse are smart enough to understand

0 0

Post a comment