I’ve just bought a new ASUS ZenWatch and I’m working on a small application to extract the sensors data from the watch.
This post ( http://developer.android.com/training/wearables/apps/bt-debugging.html ) is describing the basic steps required to setup a device for debugging and to setup a debugging session. I’ve listed below some additional steps to help with the troubleshooting if things doesn’t work as planned.
Android Debug Bridge (adb)
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:
- A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as DDMS also create adb clients.
- A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
- A daemon, which runs as a background process on each emulator or device instance.
Setup Devices for Debugging
- Enable USB debugging on the handheld:
- Open the Settings app and scroll to the bottom.
- If it doesn’t have a Developer Options setting, tap About Phone (or About Tablet), scroll to the bottom, and tap the build number 7 times.
- Go back and tap Developer Options.
- Enable USB debugging.
- Enable Bluetooth debugging on the wearable:
- Tap the home screen twice to bring up the Wear menu.
- Scroll to the bottom and tap Settings.
- Scroll to the bottom. If there’s no Developer Options item, tap About, and then tap the build number 7 times.
- Tap the Developer Options item.
- Enable Debug over Bluetooth.
Set Up a Debugging Session
- On the handheld, open the Android Wear companion app.
- Tap the menu on the top right and select Settings.
- Enable Debugging over Bluetooth. You should see a tiny status summary appear under the option:
Host: disconnected Target: connected
- Connect the handheld to your machine over USB.
- In the Android Studio open the Terminal (Alt+F12 Windows) and run:
adb forward tcp:4444 localabstract:/adb-hub adb connect localhost:4444
Note: You can use any available port that you have access to.
- adb forward forwards socket connections from a specified local port to a specified remote port on the emulator/device instance. Map a socket through the phone that is paired to your Wear device.
- adb connect will connect to the device
- A message will appear on the phone to allow Wear Debugging, press OK
- In the Android Wear companion app, you should see the status change to:
Host: connected Target: connected
Well, this is the happy flow.
While debugging I’ve encountered some issues, especially after disconnecting the phone from the USB cable.
First, print a list of all attached emulator/device instances:
adb devices List of devices attached LGD855bxxxxx device
In this case you can see only the phone and not the watch, so you will need to execute
adb forward tcp:4444 localabstract:/adb-hub adb connect localhost:4444
In other cases you may get the error message
error: more than one device/emulator
You may need to terminates the adb server process:
adb kill-server
Now you can execute the adb forward and adb connect commands
adb forward tcp:4444 localabstract:/adb-hub adb connect localhost:4444
If you get an error message
error: device unauthorized.
Try revoking the permissions on the device – Developer options -> Revoke USB debugging authorizations. Then plug the device in and accept it again.