10

I am developing an Android app and I am using Macbook Pro, Android Studio 2.1.2 Build #AI-143.2915827, JRE 1.8.0_91 and Samsung S6 device with Android 6 to test my apps. The problem is that android studio is disconnecting my device after sometime and it is not even showing me in list. I have tried almost every possible solution I have found on internet.

1) Kill adb server and start it again,
2) Unplug and plug back in device,
3) Unplug device, turn off developer mode, turn on developer mode in device, clear usb debugging authorizations, plug back in device,
4) Change SDK default location in macbook,
5) Restart test device and plug in,
6) Download updated SDK and replace old platform-tools folder 
7) Tried changing cables
8) Cleaned and reformatted Macbook with new OS

(I found sixth solution here)

and almost every single suggestion/answer I found online. But still it is not working. So does anyone have any idea how can I fix this problem? I am not able to test my application on this device. I do not have any other device and I don't have any other option to test my app. Can anyone tell me if there is a fix for this issue where android studio disconnects test device frequently?

Thanks.

Viral Joshi
  • 317
  • 2
  • 15

4 Answers4

6

I had been facing the same issue as well. On some digging, found out that the issue has already been reported and a possible fix might come out soon. Use following script as a workaround fix for disconnection issue -

#!/bin/bash

cat << EOF
###########################################################
# Workaround adb disconnecting issue on macOS Sierra
#
# More info:
# https://code.google.com/p/android/issues/detail?id=219085
# credits to: hans...@meetme.com, vs...@google.com
###########################################################

EOF

function each_device() {
  DEVICES=( $(adb devices | tail -n +2 | cut -sf 1) )

  for DEVICE in ${DEVICES[@]}
  do
    adb -s ${DEVICE} $@
  done
}

function monitor_adb () {
  adb start-server
  echo "[$(date)] adb started"

  while [ "$(each_device shell echo 1)" ]; do sleep 5; done

  echo "[$(date)] adb is broken, restarting"

  adb kill-server
  adb start-server || adb start-server
  each_device reverse
}

while [ true ]; do time monitor_adb ; done

Just save the above code as .sh file and run it using terminal. Now you will not face disconnection issue.

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • 1
    didn't work on AndroidStudio v:2.3 (adb v:1.0.36) on OSX, still have to remove the cable and attach again to get the device back! – Abduliam Rehmanius Apr 12 '17 at 18:40
  • 1
    Are you sure code is always running in terminal? Btw I haven't face this issue in a while with recent Mac OS and Android Studio updates. @AbduliamRehmanius – Rohan Kandwal Apr 12 '17 at 19:06
  • Yes running the script from the terminal.app, the script does detect "daemon not running. starting it now on port...." but it keeps on restarting adb every 3 seconds and device is not re-detected – Abduliam Rehmanius Apr 12 '17 at 20:08
  • @AbduliamRehmanius Have you tried different cable ? Because it worked for me when I had the same issue. – Rohan Kandwal Apr 12 '17 at 20:28
  • 1
    I restarted a little while ago and it appears to be doing the job now, not sure why it wasn't working previously, thanks for the answer (y) – Abduliam Rehmanius Apr 12 '17 at 20:42
  • It Works!!! Second day, script wasn't running, device went invisible in debugger window, started the script and device came back ... hopefully device's usb port will live longer now .... yayyy :p – Abduliam Rehmanius Apr 14 '17 at 14:29
5

For me it was changing the usb port that fixed it.

Ahmed U3
  • 698
  • 5
  • 9
1

Update your Android SDK Platform-tools to version 24.0.4 or later

Check out the issue report here

Giorgio Fellipe
  • 304
  • 1
  • 2
  • 10
1

I fixed it by changing from a USB 3.0 to a USB 2.0. Similar answer here: Android device keeps disconnecting from adb