Hide chapters

Android Debugging by Tutorials

1 min

Section I: Debugging Basics

Section 1: 8 chapters
Show chapters Hide chapters

Welcome to the First Edition of Android Debugging by Tutorials, created for Kotlin 1.6 and Android Studio 2021.2.1!

Android Debugging focuses on explaining how to debug your app and avoid unexpected app behavior. Once you read this book, you’ll be able to find every bug or issue inside your app, fix it and move your app to a higher level. You won’t doubt whether your end users will experience weird results or bad app performance anymore. You’ll be aware of all issues reproduced at least once and know which steps to take to resolve them.

The most important part is getting familiar with Android Studio’s debugging tools. Once you tackle each of them and find out what they offer, you won’t ever stop using them!

It’s easy to notice and resolve bugs that are visible on the UI or can be experienced while using the app. The problem arises when you have hidden bugs that can happen occasionally or when your app structure or architecture leads to memory or CPU management issues.

Thankfully, Android Studio contains built-in profilers that can present these issues to you in a specific way. You only need to learn how to use and interpret these profilers. Lucky you! This book will teach you everything from scratch.

At the moment of publishing this book, there were no other guiding books based on the Android debugging topic. This is an excellent opportunity for you to learn something new from the debugging field and extend your skills while having everything related to debugging apps in one place.

You’ll start with learning debugging basics and simple mechanisms which you can use to find and investigate bugs. After you acknowledge the basics, you’ll move to more complex tools. Don’t worry, you don’t need to install any other software for this book. Everything you need is already prepared for you in Android Studio!

With a lot of practice, this book will make you a debugging expert! But don’t stop here! The book contains some great references which you can use to continue your debug journey.

How to read this book

In this book, each chapter teaches about a specific debugging tool. It also contains a simple, practical assignment through which you learn how to use the tools faster and test your existing knowledge.

The book doesn’t contain a lot of programming theory. It’s more focused on explaining tool mechanisms, their options, actions and results. Understanding these tools is the first step in building more performant apps.

If you want to notice even the smallest detail, read these chapters in order. Chapters are created and sorted so Android beginners can easily follow them. However, if you’re an advanced developer, there’s a possibility you’d like to skip some chapters. In case that happens, be sure to continue with the starter project attached to the chapter you’re skipping to. Every starter project corresponds to the app state as it was at the end of the previous chapter. So, to have everything functional for the next step, remember to switch to the correct app package.

There is only one sample app used in the book called Podplay, but it’s full of bugs that you’ll try to fix while going through this book. That means don’t expect a fully functional and top-quality app at the beginning. This app should provide enough examples to practice inspecting and resolving issues. In case the app looks familiar to you, there is a possibility you have already used it while reading our book Android Apprentice.

Currently, the most popular language for building Android apps is Kotlin. It’s also Google’s preferred language for Android because of its simplicity. Therefore, this book and sample app use Kotlin code to make you up to date with modern technologies. For running the sample app, you need to use Android Studio.

Most of this book’s steps focus on manipulating the Android Studio built-in tools and their actions. There are a few places where you’ll need to modify the code inside the sample app. You can either type the code in Android Studio immediately, or you can tackle the issue on your own and get back to the book to reveal the solution.

To make the book more interesting and to give you a chance to test what you’ve learned, we prepared several challenges that you can find near the chapter’s end.

Every chapter contains one or more references that you can follow to learn more about related topics.

This book is split into two main sections:

Section I: Debugging Basics

Debugging is the core of every development process. This term represents steps for detecting and fixing issues that can cause unexpected behavior in your app.

In this section, you’ll learn:

  • Chapter 1: Getting Started — In the first chapter, you’ll get familiar with the sample app used inside the book. You’ll find out how to use the IDE tools and prepare your debugging environment for usage. This chapter will teach you the basics of Android Debug Bridge and how to attach a debugger to a running app.

  • Chapter 2: Navigating Your Code With Breakpoints — Once you prepare your debugging tools, you’ll start with the basics of debugging: breakpoints. You’ll learn how to use breakpoints to pause your running app at a certain point and navigate through methods while the app is paused.

  • Chapter 3: Logcat Navigation & Customization — Through this chapter, you’ll find out how the Logcat tool works and to add your logs. Logcat has some great features like customizing stack traces per your needs so you can easily manage logs.

  • Chapter 4: Analyzing the Stack Trace — Dive deep into using stack traces and tools which help navigate through them. Learn how to read stack traces and find the source of bugs and issues by using links to code lines provided inside the stack trace.

  • Chapter 5: Watches & Evaluating the Code — After you understand the debugging basics, you’ll reveal how to evaluate code by executing code lines while the app runs. This chapter also explains reading and watching variables and how Debug windows work.

  • Chapter 6: Layout Inspector — If you’re wondering how to inspect UI components built inside layouts, Chapter 6 will tell you how. You’ll see how Layout Inspector presents the current screen shown in your app. You’ll learn how to preview all UI layers and switch between them. Another thing mentioned here is handling accessibility issues with Colorblind tests as an example.

  • Chapter 7: Debugging Databases — In this chapter, you’ll learn about debugging any database included in your app. For this purpose, you’ll use the Database Inspector overview. You’ll also learn how to execute DAO Queries and custom SQL Queries on a live database.

  • Chapter 8: Debugging WorkManager Jobs With Background Task Inspector — The last chapter in this section will teach you how to handle debugging operations running on background threads. You’ll use the Background Task Inspector tool, which gives you an option to view and optimize background tasks.

Section II: The Android Profiler

Now that you know how to manage the debugging process, you’ll start learning more complex tools. In this section, you’ll meet a powerful set of Android Profiler tools. This tool package provides gear for examining app performance in depth.

Along the way, you’ll find out about:

  • Chapter 9: Profile CPU Activity — The opening chapter will introduce you to the CPU Profiler. This huge and very capable tool contains several timelines for tracking CPU activity and records detailed information in the form of system, method and function traces.
  • Chapter 10: Profile Memory Usage — In this chapter, you’ll understand how to use Memory Profiler to inspect memory allocations and investigate where memory leaks are in your app. You’ll also focus on capturing heap dumps.
  • Chapter 11: Profile Network Activity — Go on a journey to create or view an existing API call using Network Profiler. Then, inspect and debug the network call using options provided in the Network Profiler.
  • Chapter 12: Android Energy Profiler — The last chapter in this book will present how to use Energy Profiler to resolve issues with long-running services in your app. After that, you’ll read about wake locks, jobs and alarms. With this knowledge, you’ll be able to reduce draining the battery and provide a good user experience for the end user.
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2023 Kodeco Inc.