twiceyuan
9/22/2016 - 9:55 AM

Workaround adb disconnecting issue on macOS Sierra

Workaround adb disconnecting issue on macOS Sierra

#!/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 monitor_adb () {
  adb start-server
  echo "[$(date)] adb started"

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

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

  adb kill-server
  adb start-server || adb start-server
  adb reverse tcp:8081 tcp:8081
}

while [ true ]; do time monitor_adb ; done