How to avoid detach of Android Debugger while debugging Android Process?


OVERVIEW: 

Recently, I came across this problem many times where I attached the debugger to the Android Process, debug breakpoints were hit and I started evaluating some values or doing step over or step into debugging and suddenly, App isn’t responding dialog comes and debugger detaches from the process.

To avoid detaching of the debugger from the Android Process, we can set our app as a debug app from the Developer options or from ADB. 

HOW TO SET OUR APP AS A DEBUG APP?

FROM DEVELOPER OPTIONS : 

  1. Go to Settings, scroll down to Developer options. (If Developer options is not seen, Go to About Phone setting and tap on Build Number 5 times to enable Developer options).
  2. Inside Developer options, enable USB debugging.
  3. Go to Select debug app option and click on it.
  4. Select your application which you want to debug from the application list.

The screenshots below show the above steps.

Kudos! You have selected your app as a debug app.

If you want to clear the debug app, select nothing from the application list.

FROM ADB COMMAND : 

We can also use adb command to select and clear debug app. It’s more quicker and convenient than using Developer options.

adb command to select debug app : 

adb -s <your device name> shell am set-debug-app -w –persistent <your app package name>

can be used if more than one device/emulator are connected.

otherwise, 

adb shell am set-debug-app -w –persistent <your app package name> 

can be used.

Here, 

-w flag is what sets the Wait For Debugger option in Developer options. You can avoid using this flag if you do not want to enable this option.

–persistent flag tells the system to save this, and not treat this as a one-time action.

adb command to clear debug app : 

adb -s <your device name> shell am clear-debug-app

can be used if more than one device/emulator are connected.

otherwise, 

adb shell am clear-debug-app 

can be used.

Thanks for reading, 

Cheers!

Leave A Comment

Your email address will not be published. Required fields are marked *