title: Unable to attach debugger in Android Studio - localhost:8600 java.net.ConnectException
body: <p>I cannot attach the debugger in Android Studio while running debug on a phone.</p>
  
  <p>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:</p>
  
  <blockquote>
    <p>I/System.out: Sending WAIT chunk<br>
    W/ActivityThread: Application  is waiting for the debugger on port 8100...</p>
  </blockquote>
  
  <p>Or</p>
  
  <blockquote>
    <p>failed to open debugger port localhost:8600 java.net.ConnectException "connection refused"</p>
  </blockquote>
  
  <p>and the App says:</p>
  
  <blockquote>
    <p>Waiting For Debugger<br>
    Application  (process ) is waiting for the debugger to attach.<br>
    Force Close</p>
  </blockquote>
  
  <p>Android Studio version:</p>
  
  <blockquote>
    <p>Android Studio 2.2.2<br>
    Build #AI-145.3360264, built on October 18, 2016<br>
    JRE: 1.8.0_112-release-b05 x86_64<br>
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o</p>
  </blockquote>
  
  <p>Mac version:</p>
  
  <blockquote>
    <p>10.11.6 (15G1004)</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>I have been able to run the app in debug on other computers (both Windows and Mac) with the same phones.</p>
  
  <p>Various approaches I have tried from hours of debugging and online searching:</p>
  
  <ol>
  <li><p>Invalidate Caches/Restart Android studio</p></li>
  <li><p>Check for anything else running on ports 8100, 8600, 8601, etc., nothing comes back when I run the following from bash:</p>
  
  <pre><code>$ # 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
  </code></pre>
  
  <p>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
      $ </p></li>
  <li><p>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.</p></li>
  <li><p>Searching for and killing adb processes</p>
  
  <pre><code>ps aux | egrep '(adb|java)'
  ... then doing `kill &lt;pid&gt;` or `kill -9 &lt;pid&gt;` if necessary for the found ones
  </code></pre></li>
  <li><p>Restart Android studio</p></li>
  <li><p>Restart my computer</p></li>
  <li><p>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”</p></li>
  <li><p>Completely uninstall and reinstall android studio - e.g., <a href="https://stackoverflow.com/a/18458893/376489">https://stackoverflow.com/a/18458893/376489</a> - weirdly, I think this worked for one run of the debugger and then not again…</p></li>
  <li><p>Tried Run > Attach debugger to Android Process - this didn’t help</p></li>
  <li><p>Tried running:</p>
  
  <pre><code>~/Library/Android/sdk/platform-tools/adb kill-server &amp;&amp;
   ~/Library/Android/sdk/platform-tools/adb start-server
  </code></pre></li>
  <li><p>Tried unchecking Run > Edit Configurations > Run/Debug Configurations > Skip installation if APK has not changed</p></li>
  <li><p>Check System Preferences > Security &amp; Privacy > Firewall - this is turned off</p></li>
  <li><p>Update 1: tried revoking permissions on the phone as well as restarting it</p></li>
  <li><p>Update 1: muted all breakpoints Android Studio</p></li>
  </ol>
  
  <p>Are there any other ideas for what might be going wrong or anything meaningful in the details I added above?</p>