NOW Hiring

Quick links

Debugging Android applications - Tutorial

Lars Vogel

Version 2.1

29.04.2013

Debugging Android applications

This tutorial describes how to debug Android applications.


Table of Contents

1. Debugging Android applications
1.1. Android debuggable attribute in the AndroidManifest.xml
1.2. Turn debugging on at runtime in Eclipse
2. Eclipse debugging
3. Exercise: Debugging
3.1. Import example project
3.2. Debug the creation of the list items
3.3. Debug list item click behavior
4. About this website
5. Links and Literature
5.1. Android Resources
5.2. vogella GmbH training and consulting support

1. Debugging Android applications

1.1. Android debuggable attribute in the AndroidManifest.xml

If you develop Android applications you can debug them via Eclipse. To enable debugging an a real Android device you need to add the android:debuggable="true" flag to the application segment in your AndroidManifest.xml file. The ADT tooling sets this flag automatically for debug builds based on the constant DEBUG of the BuildConfig class. This class is automatically updated by the ADT.

1.2. Turn debugging on at runtime in Eclipse

The JVM requires that you start a Java program in Debug mode to debug it. Android allows you to turn debugging for a running application on at runtime via the Debug button in the Device view of the DDMS perspective as depicted in the following screenshot.

Activate debugging

After turning debugging on in this view, the next time a Breakpoint is encountered Eclipse allows you to debug the process.

2. Eclipse debugging

Android applications can be debugged similar to Java applications. See Eclipse debugging tutorial for details.

3. Exercise: Debugging

3.1. Import example project

Download the zip file from http://www.vogella.com/download/androidtest/countries.zip and import the Android project from into your workspace via the FileImport...GeneralExisting Projects into Workspace menu path.

3.2. Debug the creation of the list items

After launching the application you suppose to see a list of countries registered in the system. There is a bug in the implementation which causes the list to show empty strings.

  1. Launch the application normally.

  2. Realizing that their is a problem, you switch Debug mode on in the DDMS perspective.

  3. Put a breakpoint in MainActivity.onCreate(Bundle savedInstanceState) and re-launch the activity.

  4. Execute CountryUtils.getCountries() statement and check the value of "countries" variable. If you believe the value is incorrect, use "Step into" debug function to find the issue.

  5. Fix the issue.

  6. Launch the application and make sure the list of countries is shown correctly.

3.3. Debug list item click behavior

If you click an item in the list, application will show a toast message with the name of the country clicked. There is a bug in the applications which makes this function not working properly.

  1. Launch the application normally.

  2. (Try to) debug MainActivity.onListItemClick() method and fix the issue.

  3. Launch the application and make sure correct item is show in the toast.

4. About this website

5. Links and Literature

5.2. vogella GmbH training and consulting support

TRAINING SERVICE & SUPPORT
The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”. The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.