This document provides an overview of debugging Android applications using Eclipse and Android Virtual Devices (AVDs). It discusses the Eclipse DDMS perspective for debugging, creating and using AVDs to emulate Android devices, and examining manifest files. It also covers string and image resources, and potential issues with the automatically generated R.java file.
4.18.24 Movement Legacies, Reflection, and Review.pptx
Debugging Android Apps & Manifests in Eclipse
1. Software Engineering Large Practical
Debugging Android Applications,
working with Android Virtual Devices,
and Manifests
Stephen Gilmore
School of Informatics, University of Edinburgh
October 10th, 2012
Stephen Gilmore Software Engineering Large Practical
2. Eclipse DDMS perspective
The Dalvik Debug Monitor Server (DDMS) is a debugging tool for
Android. It provides port-forwarding services and screen capture on
the device. It provides information about process, threads and
heap usage. It contains the logcat console which allows us to see
diagnostic error messages. It allows the developer to simulate the
effect of an incoming call or SMS, or to simulate setting the
phone’s location.
Stephen Gilmore Software Engineering Large Practical
3. DDMS perspective in Eclipse
.05.14.png
Stephen Gilmore Software Engineering Large Practical
4. Set your location
Stephen Gilmore Software Engineering Large Practical
5. LogCat — a log of events on the phone
Stephen Gilmore Software Engineering Large Practical
6. File Explorer — see files on the phone
.07.32.png
Stephen Gilmore Software Engineering Large Practical
7. Devices — see processes in the emulator
.10.14.png
Stephen Gilmore Software Engineering Large Practical
9. Creating an Android Virtual Device
An Android Virtual Device (AVD) is an emulator configuration
which allows the developer to replicate the effect of having an
actual Android device such as a phone or a tablet. The AVD allows
you to specify hardware and software settings which will be
emulated by the Android Emulator. When creating a new AVD you
specify the target API (i.e. a particular version of Android).
Stephen Gilmore Software Engineering Large Practical
11. Android Virtual Device (AVD) manager
Stephen Gilmore Software Engineering Large Practical
12. Create a new AVD (Click New...)
Stephen Gilmore Software Engineering Large Practical
13. Create new Android Virtual Device
.21.54.png
Stephen Gilmore Software Engineering Large Practical
14. Starting the emulator
Having defined the type of AVD that we are interested in, we can
start one running and investigate the functions of our virtual
device.
Stephen Gilmore Software Engineering Large Practical
15. Start the new AVD
.22.07.png
Stephen Gilmore Software Engineering Large Practical
18. Emulator home page is displayed
.03.13.png
Stephen Gilmore Software Engineering Large Practical
19. Click to display options
.03.14.png
Stephen Gilmore Software Engineering Large Practical
20. Functions of the phone
.03.57.png
Stephen Gilmore Software Engineering Large Practical
21. Developer tools
There are some tools on the device which are specifically there to
help developers (API Demos and Dev Tools). The developer tools
allow us to see (for example) processes which are running on the
phone.
Stephen Gilmore Software Engineering Large Practical
25. API demos
There are some tools on the device which are specifically there to
help developers (API Demos and Dev Tools). Using these we can
learn about the Android API features such as auto-completion.
Stephen Gilmore Software Engineering Large Practical
31. Manifest files
Every Android application must have an AndroidManifest.xml
file (with precisely that name) in its root directory. The manifest
presents essential information about the application to the Android
system, including information about intents which are messages
sent to activities, services and broadcast receivers. The manifest
also specifies permissions which the application requests (such as
the permission to connect to paired Bluetooth devices) and
libraries that it needs.
Stephen Gilmore Software Engineering Large Practical
32. Manifest files
Stephen Gilmore Software Engineering Large Practical
42. Resources and strings
An Android application may need resources such as image files and
strings. A string resource provides text strings for the application
with optional text styling and formatting.
Stephen Gilmore Software Engineering Large Practical
48. Contents of app notes.png
Stephen Gilmore Software Engineering Large Practical
49. The icon in the launcher view
Stephen Gilmore Software Engineering Large Practical
50. Editing string resources
String resources can be edited using the Android Resources editor.
Stephen Gilmore Software Engineering Large Practical
51. Application nodes
Stephen Gilmore Software Engineering Large Practical
52. Browsing
Stephen Gilmore Software Engineering Large Practical
53. Editing strings
Stephen Gilmore Software Engineering Large Practical
54. Updating a string
Stephen Gilmore Software Engineering Large Practical
55. Text in the XML view
Stephen Gilmore Software Engineering Large Practical
56. Updating a string in the Resources view
Stephen Gilmore Software Engineering Large Practical
57. The XML text is updated automatically
Stephen Gilmore Software Engineering Large Practical
58. Getting it wrong: editing the XML
Stephen Gilmore Software Engineering Large Practical
59. The bug shows up in the resources view
Stephen Gilmore Software Engineering Large Practical
60. Oh dear
Stephen Gilmore Software Engineering Large Practical
61. Android Eclipse issues
Working with hand-crafted and automatically-generated Java files
can be confusing. In particular we focus on errors involving the
automatically-generated R.java file.
Stephen Gilmore Software Engineering Large Practical
62. Oh no, Java problems . . .
Stephen Gilmore Software Engineering Large Practical
63. “Layout cannot be resolved . . . ”
Stephen Gilmore Software Engineering Large Practical
64. R.java is generated so clean the project?
Stephen Gilmore Software Engineering Large Practical
65. No good. Delete R.java and try again?
Stephen Gilmore Software Engineering Large Practical
66. R.java is regenerated but errors remain
Stephen Gilmore Software Engineering Large Practical
67. Refresh the view?
Stephen Gilmore Software Engineering Large Practical
68. No good. What now?
Stephen Gilmore Software Engineering Large Practical
69. Close the project and reopen it?
Stephen Gilmore Software Engineering Large Practical
70. Reopening the project. Praying . . .
Stephen Gilmore Software Engineering Large Practical
71. Didn’t work :-( but look at this . . .
Stephen Gilmore Software Engineering Large Practical
72. Moving the folder fixes the problem :-)
Stephen Gilmore Software Engineering Large Practical
73. Moving the folder fixes the problem :-)
Stephen Gilmore Software Engineering Large Practical