MrColes
MrColes

Reputation: 2503

Unable to attach debugger in Android Studio - localhost:8600 java.net.ConnectException

I cannot attach the debugger in Android Studio while running debug on a phone.

I’m currently using a Samsung S4, running Android 4.4.4 (but have tried an S5, S6, S7, and Moto E phone on various Android versions). It times out when I try to run it with either of the following errors:

I/System.out: Sending WAIT chunk
W/ActivityThread: Application is waiting for the debugger on port 8100...

Or

failed to open debugger port localhost:8600 java.net.ConnectException "connection refused"

and the App says:

Waiting For Debugger
Application (process ) is waiting for the debugger to attach.
Force Close

Android Studio version:

Android Studio 2.2.2
Build #AI-145.3360264, built on October 18, 2016
JRE: 1.8.0_112-release-b05 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Mac version:

10.11.6 (15G1004)

I can successfully connect and run the application, I just can’t get the debugger to attach when I do Run > Debug App > select the connected phone > OK.

I have been able to run the app in debug on other computers (both Windows and Mac) with the same phones.

Various approaches I have tried from hours of debugging and online searching:

  1. Invalidate Caches/Restart Android studio

  2. Check for anything else running on ports 8100, 8600, 8601, etc., nothing comes back when I run the following from bash:

    $ # while Android studio is trying to attach the debugger
    $ lsof -i :8100
    $ lsof -i :8600
    COMMAND  PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    

    studio 6282 peter 125u IPv4 0x973c7e31bda641ab 0t0 TCP 192.168.1.16:64022->ip-166-62-27-181.ip.secureserver.net:asterix (SYN_SENT) $ lsof -i :8601 $ $ # after Android studio fails to attach the debugger $ lsof -i :8100 $ lsof -i :8600 $ lsof -i :8601 $

  3. Run Tools > Android > Android Device Monitor - it shows my device, but I can’t run Android Device Monitor while I’m trying to debug the app, it says, “Monitor will be closed to enable ADB integration. Continue?” I haven’t found anything useful here.

  4. Searching for and killing adb processes

    ps aux | egrep '(adb|java)'
    ... then doing `kill <pid>` or `kill -9 <pid>` if necessary for the found ones
    
  5. Restart Android studio

  6. Restart my computer

  7. Update Java JDK from the Oracle website—however, I’m not sure why Android Studio still says, “JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o”

  8. Completely uninstall and reinstall android studio - e.g., https://stackoverflow.com/a/18458893/376489 - weirdly, I think this worked for one run of the debugger and then not again…

  9. Tried Run > Attach debugger to Android Process - this didn’t help

  10. Tried running:

    ~/Library/Android/sdk/platform-tools/adb kill-server &&
     ~/Library/Android/sdk/platform-tools/adb start-server
    
  11. Tried unchecking Run > Edit Configurations > Run/Debug Configurations > Skip installation if APK has not changed

  12. Check System Preferences > Security & Privacy > Firewall - this is turned off

  13. Update 1: tried revoking permissions on the phone as well as restarting it

  14. Update 1: muted all breakpoints Android Studio

Are there any other ideas for what might be going wrong or anything meaningful in the details I added above?

Upvotes: 25

Views: 21559

Answers (12)

Victor Pal&#233;ologue
Victor Pal&#233;ologue

Reputation: 2352

There is a known issue with Android Studio 4.2.1 on Ubuntu 20.04 when debugging native code.

There is an easy way to check if you are concerned, just run the following command line that should not finish with an error:

${android-studio-dir}/bin/lldb/bin/LLDBFrontend

Upvotes: 0

Dwebtron
Dwebtron

Reputation: 816

This problem was driving me crazy for about 2 weeks. What finally fixed it for me was changing "auto" to "java" in the debugger process selection window like this: enter image description here

Upvotes: 3

RelativeGames
RelativeGames

Reputation: 1593

Simply not using my google pixel 1st gen and using my new Nokia 7 plus fixed this issue :).

Upvotes: 0

Vishakha Tyagi
Vishakha Tyagi

Reputation: 21

Try using below commands on terminal-

  1. adb kill-server

  2. adb start-server

It works well.

Upvotes: 1

Balazs F.
Balazs F.

Reputation: 410

I am using a real device. Simply deleting the app on the device, and then running from Android Studio solved this issue.

It seems Android Studio had trouble with overwriting the file that was already on the phone.

Upvotes: 6

Andrew Patlan
Andrew Patlan

Reputation: 1

At first i tried all the above ways, did not help. I have two computers with same settings. But at one worked at other error. It's given me an idea that it can be "hardware" problem. I switched USB to other slot with USB3.0 and used short cable and WOW it began work. I suggest there some delay in USB2.0 (polling), therefore process begin out of synch.

Upvotes: -2

Robin Davies
Robin Davies

Reputation: 7832

I have the opposite problem with Android Studio 3.3, trying to debug a wi-fi-connected phone.

After selecting the device in Android Studio, I receive the following message:

Error running 'app': Unable to open debugger port (localhost:8600): java.net.ConnectException "Connection refused: connect"

I also have IPV-6 enabled on my network.

The issue is that "localhost" resolves to ::1 on my machine by default, but ADB studiously binds explicitly to 127.0.0.1. I happen to know this because I spent the day trying to make ADB connect to emulators running on a remote machine (not since Android 4.4 unfortunately.

To solve the problem, add the following line to \windows\system32\drivers\etc\hosts:

127.0.0.1 localhost

Upvotes: 2

Sushant Gosavi
Sushant Gosavi

Reputation: 3845

Support for a true debug build. Developers no longer need to add the android:debuggable attribute to the tag in the manifest — the build tools add the attribute automatically. In Eclipse/ADT, all incremental builds are assumed to be debug builds, so the tools insert android:debuggable="true". When exporting a signed release build, the tools do not add the attribute. In Ant, a ant debug command automatically inserts the android:debuggable="true" attribute, while ant release does not. If android:debuggable="true" is manually set, then ant release will actually do a debug build, rather than a release build.

In my case i struggling this issue with 5 hour and found that the

minifyEnabled true is the main culprit so change minifyEnabled false work for me

My app build.gradle file look like

 buildTypes {
        debug {
            signingConfig signingConfigs.debug
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }

Upvotes: 3

MrColes
MrColes

Reputation: 2503

Quite embarrassing, but it looks like some time ago I had entered an ip address into my /etc/hosts file to test something as localhost and never removed it. I found a comment on another post saying to check that the following is in your /etc/hosts:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

Upon commenting out that spurious line, the debugger is now working. Given I have a dozen or so other IPs in that file (so I can more easily test remote hosts with a friendly name), I must have not noticed this one at the bottom. I think a more foolproof approach to verifying if this is the problem or not is to ping localhost and verify that it resolves to the ip address of 127.0.0.1, e.g.,

$ ping localhost
PING localhost (127.0.0.1): 56 data bytes

Great comments and suggestions from other folks here too, thanks!

Upvotes: 27

Shubham
Shubham

Reputation: 165

I also got same error and this thing worked for me

1. Open Android Studio -> Terminal
2. Change directory to $Android SDK Path$\platform-tools
3. Write command adb get-state and hit enter.

Then you will get this output

* daemon not running. starting it now on port 5037 *
* daemon started successfully *

Upvotes: 2

Nantoka
Nantoka

Reputation: 4253

I just experienced the same issue. It seems, as if Android Studio Version 2.2 has some issues with a non-attaching debugger as you can see for example here and here.

In my case the following helped:

  • Remove the launch profile for your app by going to Run -> Edit Configurations... and removing the profile there. Don't forget to hit the OK button after you have removed the profile. :)
  • Create a new launch profile from scratch by again going to Run -> Edit Configurations..., hitting the + button, selecting an Android App launch profile and selecting your start module. The other default values of the profile were just fine.

Hope this helps you as well.

Upvotes: 12

Rajesh.k
Rajesh.k

Reputation: 2447

1.try cleaning project Build->clean project

2.do file->Invalidate/cache restart if above not helps you..

3.try to change the data cable you are using to connect your phone.

if nothing above helps, install Android wifi ADB plugin and try to do debug over wifi.

Upvotes: 4

Related Questions