Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attaching debugger to Android process automatically in Android Studio

Tags:

Is there any way to configure Android Studio to attach the debugger to an android process automatically (specifically for a background process started by a service)? I want to have breakpoints stop execution in Android Studio for services that are running in a background process. I have been able to manually start a started service and attach the debugger manually to get this to work. I was just wondering if there is someway to configure Android Studio to do this automatically.

Edit: I probably should have mentioned first that I wanted to attach the debugger to a background android process created from starting or binding to a service.

like image 467
Daniel Aquino Avatar asked May 11 '15 18:05

Daniel Aquino


People also ask

Is waiting for the debugger to attach Android studio?

If it is stuck waiting for a debugger means it is not attached to the app. You have to manually attach by clicking on Attach Debugger to Android process. It is on the right side of the run icon.

What does attaching to debugger mean?

However, there are some situations where you must debug the application in a different way — by attaching to its process. < i>Attaching</i><i> to the process</i> means telling the CPU to send the instructions in the executable code to a debugger before they're executed by the CPU.

How can you debug your app when it's already released?

Move your production google-services. json file into the release folder. Then copy your debug one into the app folder (this is where the console instructs you to put it). From now on, the release build will always use the google-services.


2 Answers

If you have the package name, you type adb shell am set-debug-app -w packagename to let it wait until debugger connected.

like image 107
smoothdvd Avatar answered Sep 19 '22 11:09

smoothdvd


You can run an app with a debugger directly attachted to it at startup by using this little button:

Android Studio menu bar

like image 42
davidgiga1993 Avatar answered Sep 18 '22 11:09

davidgiga1993