Debugging & Profiling
Master Android Studio's debugging and profiling tools: breakpoints, Logcat, Timber, Memory Profiler, LeakCanary, CPU Profiler, Network Inspector, and Layout Inspector.
Debugging Overview
Debugging is the process of finding and fixing bugs. Android Studio provides powerful tools:
- Debugger — pause execution, inspect variables, step through code
- Logcat — real-time log output from the device
- Layout Inspector — inspect the live UI hierarchy
- Android Profiler — CPU, Memory, and Network analysis
- Database Inspector — view and query Room databases live
Logcat — Your First Debug Tool
Use Log to print messages to Logcat. Use a TAG to filter your logs:
import android.util.Log
class UserRepository {
companion object {
private const val TAG = "UserRepo"
}
fun fetchUsers() {
Log.d(TAG, "fetchUsers() called") // Debug
Log.i(TAG, "Fetching ${users.size} users") // Info
Log.w(TAG, "Cache is empty") // Warning
Log.e(TAG, "Network error: $exception") // Error
}
}All lessons in this course
- Unit Testing with JUnit
- Mocking with Mockito
- UI Testing with Espresso
- Debugging & Profiling