
There are several functions for logging output, taking the form Log.v(), Log.d(), Log.i(), Log.w(), or Log.e(). In an Android app, the best practice for logging output is using Log class. In the previous lessons, you used Kotlin's println() statement to produce text output. Make sure the language is set to Kotlin, and leave everything else unchanged.Īfter creating the project, you'll be greeted with a new Android Studio project, showing a file called MainActivity.kt. On the New Project screen, choose Empty Activity.Start by creating a new Android Studio project, as shown.
Rather than use a large and complex app, we're going to start with a blank project to demonstrate log statements and their usage for debugging.
A computer with Android studio installed. Capture screenshots and animated GIFs from the Android Emulator.
Search for error messages to solve application crashes. How to find meaningful information in a stack trace. Use logs as a simple and powerful debugging tool. You know how to navigate a project in Android Studio.īy the end of this codelab, you'll be able to. Finally, you'll learn how to research bugs on your own, as well as learn how you can capture output from the Android emulator, as either a screenshot or a GIF of your running app. You'll also learn to read error message logs, called stack traces, to identify and solve bugs. In this codelab, you'll learn how to use logging in Android Studio, and how it can be used as a debugging tool. The famous computer scientist Brian Kernighan once said that "the most effective debugging tool is still careful thought, coupled with judiciously placed print statements." While you may already be familiar with Kotlin's println() statement from previous codelabs, professional Android developers use logging to better organize their program's output. The process of fixing bugs is called debugging. For example, see the version details of Google Maps below: It's not uncommon to see entire app releases dedicated to fixing bugs. All developers, regardless of experience, introduce bugs when they write code, and one of the most important skills for an Android developer is to identify and fix them. A bug is an error in a piece of software that causes unintended behavior, such as an app crashing, or a feature not working as expected.
Anyone who's used a piece of software has most likely encountered a bug.