Programming
Debugging with Android Studio stuck at Waiting For Debugger forever
Encountering the dreaded “Waiting For Debugger” message in Android Studio, seemingly stuck forever, can be a major roadblock for Android developers. This frustrating issue prevents you from stepping through your code, inspecting variables, and ultimately squashing those pesky bugs that inevitably arise during development. Debugging is an essential part of the development process, and when your debugging tools fail, productivity grinds to a halt. Whether you’re a seasoned Android developer or just starting your journey, understanding the common causes and solutions for this problem is crucial. This article will explore the various reasons why your Android Studio debugging session might be stuck and provide a comprehensive guide to troubleshooting and resolving this issue, allowing you to get back to building awesome Android applications. We’ll cover everything from basic configuration checks to more advanced debugging techniques, ensuring you have the tools and knowledge to tackle this problem head-on and prevent it from derailing your development workflow.
Common Causes for “Waiting For Debugger”
Several factors can contribute to Android Studio getting stuck at “Waiting For Debugger”. One frequent culprit is incorrect debugging configurations within Android Studio itself. This could involve misconfigured run/debug configurations, incorrect project settings, or even outdated versions of the Android SDK or Android Studio. Another potential issue lies within the Android device or emulator you’re using for testing. If the debugger isn’t properly enabled or if the device isn’t correctly connected to your development machine, Android Studio will struggle to establish a debugging session. Resource constraints on either your development machine or the Android device can also play a role, especially when dealing with complex applications or limited memory. Furthermore, firewalls and security software can sometimes interfere with the debugging process by blocking the necessary communication ports between Android Studio and the target device.
Another common cause is having multiple debuggers attached to the same process. This can happen if you accidentally launched the debugger twice or if another application is attempting to debug your application simultaneously. This conflict prevents Android Studio from properly attaching to the process and results in the “Waiting For Debugger” message. Furthermore, issues with your app’s build configuration, such as incorrect build variants or conflicting dependencies, can also interfere with the debugger. In some cases, simply cleaning and rebuilding your project can resolve these types of issues. Finally, problems with the Android Debug Bridge (ADB), the command-line tool used by Android Studio to communicate with Android devices, can also lead to debugging failures. Restarting the ADB server can often resolve connectivity issues and allow the debugger to attach successfully.
According to a Stack Overflow survey, approximately 30% of Android developers encounter debugging issues regularly. This highlights the importance of having a solid understanding of debugging techniques and troubleshooting strategies. Addressing these common causes proactively can save significant time and frustration during the development process.
Troubleshooting Steps: Configuration and Connection
The first step in resolving the “Waiting For Debugger” issue is to carefully review your debugging configurations within Android Studio. Begin by checking your Run/Debug Configurations (Run -> Edit Configurations). Ensure that the correct module is selected, the launch option is set to “Default Activity,” or the desired activity, and that the debugger is set to “Auto” or “Native Only” if you are using native code. Verify that the “Deploy” option is checked to ensure your application is correctly installed on the device before debugging begins. Double-check that your project’s build.gradle file has the debuggable true flag set within the buildTypes section. This flag is essential for enabling debugging capabilities in your application build.
Next, focus on the connection between Android Studio and your device or emulator. Make sure your Android device is properly connected to your computer via USB and that USB debugging is enabled in the device’s developer options. For emulators, ensure they are configured correctly and running before attempting to debug. Restarting the ADB server can often resolve connection issues. You can do this by going to “Build -> Clean Project” and then “Build -> Rebuild Project” in Android Studio, or by using the command line: adb kill-server followed by adb start-server. Confirm that Android Studio recognizes your device by running adb devices in the terminal. If your device isn’t listed, try disconnecting and reconnecting it, or restarting your computer. Sometimes, simply revoking USB debugging authorizations on your device and re-granting them can resolve connection problems.
Here’s a featured snippet-optimized paragraph: One of the most common solutions is to ensure USB debugging is enabled on your Android device. Navigate to Settings > Developer Options (this may require enabling Developer Options first by tapping the Build Number multiple times in Settings > About Phone). Look for the “USB Debugging” option and ensure it’s toggled on. This allows Android Studio to communicate with your device and attach the debugger.
Advanced Debugging Techniques
If basic configuration checks and connection troubleshooting don’t solve the problem, it’s time to explore more advanced debugging techniques. Start by examining your application’s logs using Logcat in Android Studio. Look for any error messages or exceptions that might indicate why the debugger is failing to attach. Filter the logs by your application’s package name to focus on relevant information. Breakpoints are essential for effective debugging. Ensure your breakpoints are correctly placed and that they are being hit during the execution of your application. Sometimes, breakpoints can be accidentally disabled or placed in unreachable code, preventing the debugger from pausing execution.
Consider using the Android Profiler to monitor your application’s CPU usage, memory allocation, and network activity. This can help identify performance bottlenecks or resource leaks that might be interfering with the debugger. If you’re working with native code (C/C++), ensure that your native debugging setup is correctly configured. This typically involves installing the necessary native debugging tools and configuring Android Studio to use them. Furthermore, if you’re using Kotlin coroutines, be aware that debugging them can sometimes be tricky. Use the Kotlin coroutines debugger plugin for Android Studio to simplify the process of debugging asynchronous code. If you suspect that a particular library or dependency is causing the issue, try temporarily removing it to see if the debugger starts working correctly. This can help isolate the source of the problem. You can also use the “Attach Debugger to Android Process” feature in Android Studio to manually attach the debugger to your application process. This can be useful in situations where the debugger fails to attach automatically.
Here are some key debugging tips:
- Use Logcat effectively to identify errors and warnings.
- Set breakpoints strategically to pause execution at specific points in your code.
- Utilize the Android Profiler to monitor resource usage and identify performance issues.
Resolving Specific Scenarios and Conflicts
Certain scenarios and conflicts can specifically trigger the “Waiting For Debugger” issue. One common scenario is when multiple applications are trying to use the same debugging port. Close any other applications that might be using ADB, such as other instances of Android Studio or other development tools. Firewalls can also interfere with the debugging process by blocking the necessary communication ports. Temporarily disable your firewall to see if it resolves the issue. If it does, configure your firewall to allow connections from Android Studio and the ADB server. Conflicting dependencies in your project can also cause debugging problems. Use the Dependency Analyzer in Android Studio to identify any potential conflicts and resolve them by updating or excluding the conflicting dependencies.
If you are using Instant Run, try disabling it temporarily. While Instant Run can speed up development, it can sometimes cause issues with debugging. Go to File -> Settings -> Build, Execution, Deployment -> Instant Run and uncheck “Enable Instant Run to hot swap code…”. Clean and rebuild your project after disabling Instant Run. In some cases, the issue might be related to your Gradle configuration. Ensure that your Gradle version is compatible with your Android Studio version and that your project’s Gradle files are correctly configured. Try updating your Gradle version to the latest stable release. You can find the latest version on the Android Developers website. Finally, if all else fails, consider reinstalling Android Studio and the Android SDK. This can help resolve any underlying issues with your development environment. You can download the latest version of Android Studio from the official Android Studio website.
Remember these key actions when facing conflicts:
- Close other ADB-using applications.
- Temporarily disable your firewall.
- Disable Instant Run and rebuild your project.
- Why is Android Studio stuck on "Waiting For Debugger"?
- This can be due to incorrect configurations, connection problems with the device, firewall interference, or conflicts with other applications.
- How do I enable USB debugging on my Android device?
- Go to Settings > Developer Options (enable Developer Options by tapping the Build Number multiple times in Settings > About Phone) and toggle on "USB Debugging".
- What is ADB and why is it important for debugging?
- ADB (Android Debug Bridge) is a command-line tool that allows Android Studio to communicate with Android devices and emulators. It's essential for debugging and installing applications.
- How do I restart the ADB server?
- Open a terminal and run the commands adb kill-server followed by adb start-server.
- What should I do if my device is not showing up in Android Studio?
- Make sure USB debugging is enabled, the device is properly connected, and try restarting the ADB server. Also, check if you need to install specific USB drivers for your device.
Question & Answer :
UPDATE The supposed duplicate is a question on being stucking in “Waiting For Debugger” when executing Run, while this question is on being stucking in “Waiting For Debugger” when executing Debug, the steps to produce the problem is different, and the solution(s) are different as well.
Whenever I try to use Android Studio’s Debug function, the Run status would always stuck at:
Launching application: com.astrotek.parashoot.debug/com.astrotek.ptpviewer.StarterActivity. DEVICE SHELL COMMAND: am start -n "com.astrotek.parashoot.debug/com.astrotek.ptpviewer.StarterActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.astrotek.parashoot.debug/com.astrotek.ptpviewer.StarterActivity }
While the device (Samsung Galaxy S3 Android 4.3) I’m debugging would display

This has being the case from Android Studio 0.8.8 all the way to 1.0. And on the same computer I can perform debugging using Eclipse on the same device without any issues.
So the question is what can I do to make Android Studio debugging work?
Update: The same thing happens when debugging on Nexus 7 (2013) running Android 5.0; and testing on another machine rendered the same result. I can’t be the only one encountering this issue :-/
Update: Opened a bounty since this issue is so annoying. Even re-installing the app doesn’t solve. Nexus 5 running Cyano, Win7 64. The ADB log is telling:
8568-8568/it.myapp:myprocess W/ActivityThread﹕ Application it.myapp is waiting for the debugger on port 8100... 8568-8568/it.myapp:myprocess I/System.out﹕ Sending WAIT chunk
Also, I can’t find an easy way to disconnect nor reset ADB connection in Android Studio.
Obviously is yet another Android Studio, or rather ADB bug.
Just use this command to disable it. adb shell am clear-debug-app
OR
Ensure there is nothing to wait for, by automatic uninstall from Device before each test-run, using Gradle’s uninstallAll task, as mentioned in:
stackoverflow.com/Auto uninstall before install?