Exploring Android Studio: Building and Debugging

Welcome to Part 6 of this review of the Pluralsight course Exploring Android Studio
by Larry Schiefer


Larry Schiefer

Larry Schiefer is the CTO and co-founder of HiQES, a mobile, embedded, and application development service company. Larry has over 16 years of experience leading teams, and designing and developing high performance and robust software, and is a Google GDE.

Building and Debugging With Android Studio

Building the Project

We start by learning the “Make Project” command which is found in the Build menu.
Once complete, we can find the created files in the app\build\ directory and these includes the following subdirectories:

– apk
– assets
– classes
– dependency-cache
– dex
– incremental
– libs
– manifests
– ndk
– pre-dexed
– res
– rs
– source
– symbols

Larry explains the purpose of many of these. Then we see the “Clean Project” command cleans the entire project, not just a given module.

We can build modules individually by selecting the module in the project view, right clicking on it to display the menu options, and left clicking on “Make Module”.
Or we can choose “Compile Module” from the build menu, which only compiles our XML, Java, AIDL and/or render script files.
Compile Module does not link them or package them into an APK file.

Running the App

We click the green play arrow and a dialog pops up.
We then either choose a running device and click OK, or choose the Launch emulator radio button and choose an AVD.

We see it running but then our app crashes. A stack trace is displayed in the logcat window.
Larry introduces this window and explains that we can change the log level or search for specific text here.

Debugging the App

Unlike Eclipse or Visual Studio, Android Studio does not have the debugger halt on unhandled exceptions out-of-the-box.

To turn this on, open the Run menu and click “View Breakpoints…”. The dialog that opens has an Exception Breakpoints section.
Check the “Any exception” box and uncheck the “Condition” and “Caught exception” boxes.

With this enabled the debugger now breaks, and we can see the uncaught exception is in the getText method of the resource class.
The resource ID specified is not valid. This is because we’re passing an integer instead of a resource ID.

Before we fix this, Larry explains some of the other controls available in the debug window:

– rerun app
– continue execution
– halt debugger
– breakpoint dialog
– mute all breakpoints
– frames and threads tabs
– choosing a specific thread to debug
– go to current source line of execution
– step over a line of code
– stepping into code
– stepping out of code
– drop the current frame
– run to the current cursor position
– evaluate an expression

He also goes through some of the other settings we may want to setup for breaking on exceptions.

Finally we fix the bug and rerun to verify the fix works.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s