Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any fix for Android studio keep disconnecting test device in Macbook Pro?

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.

like image 502
Viral Joshi Avatar asked Jul 28 '16 15:07

Viral Joshi


Video Answer


2 Answers

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: [email protected], [email protected]
###########################################################

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.

like image 83
Rohan Kandwal Avatar answered Sep 28 '22 06:09

Rohan Kandwal


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

like image 22
Ahmed U3 Avatar answered Sep 28 '22 05:09

Ahmed U3