Getting Started Testing Android Wear

 
 

Preface

Testing Android Wear is not an easy undertaking. It will frustrate you. This guide will help ease the pain a bit, provide a getting-started jumping-off point, and represents my best attempt at an understanding of best practices and what not to do. 

This document makes some assumptions:
- You are running a Mac environment
- You are already familiar with .bash_profile, and Terminal

If this all seems good to you still, please, read on.

Contents

I.   Paring Devices
II.  Test Environments (ADB is Your Friend)
III. Setting up New Devices
IV. Gotchas
V.  Outro and Contact Info

Pairing Devices

Devices must be paired with a phone in order to function fully for testing purposes. Here’s a guide to pairing devices that assumes that the watch has already been paired with a different phone than that which you wish to use. For security reasons, a full factory reset of the watch only is required to pair a watch with a new phone.

  1. Factory Reset the Watch (it’s very important that you only do this if you need to pair with a new phone or the wearable has system issues)
  2. Double tap the watch face, which surfaces the settings menu
  3. Click the “Settings” icon
  4. Scroll down the resulting list until you find “Factory Reset”
  5. Click this option
  6. Make sure that the phone you wish to pair with has Android Wear installed
  7. After the reset is complete, follow the prompts on the watch


Test Environments (ADB is Your Friend)

In order to successfully test Android apps in development, it helps to have a way to communicate with devices, install new builds (without the Play Store), and gather data from logs. Enter ADB, Android Debug Bridge. With this tool, you can do all of the above and much, much more. For our purposes here, we’ll suppose that you only need five commands and one common flag.

  1. Download Android the Android SDK Stand Alone Tools
  2. Follow the walkthrough, here
  3. For our purposes, we will only need the following:
    • Android SDK Tools
    • Android SDK Platform-tools

Feel free to download some emulators or whatever else you like. It will not hurt.

Once you have the SDK and all of its tools installed, activate “Developer Options” on the devices which you would like to test.

Setup Developer Options for Phone

Navigate to the following directory

         Settings > About Device

  1. Scroll to ‘Build Number’
  2. Tap on the ‘Build Number’ an inordinate amount of times (7)
  3. “You are now a developer!” should appear
  4. Navigate back to Settings
  5. Select the newly added ‘Developer Options’ from the menu
  6. Select the following option as ‘Enabled’
    • USB Debugging
  7. A dialog box will show and say “...are you sure?” You’re sure. Show them that by clicking “OK”

Setup Developer Options for Wearable (watch)

  1. Swipe from right to left on watch face to bring up settings menu
  2. Select “Settings” from the menu
  3. Scroll to the “About” item and select it
  4. Locate the “Build Number”
  5. Tap on the ‘Build Number’ an inordinate amount of times (7)
  6. “You are now a developer!” should appear
  7. Select the newly added ‘Developer Options’ from the menu
  8. Select the following option as ‘Enabled’
    • ADB Debugging
    • Debug over Bluetooth

You are now ready to manipulate your devices using the USB port on your computer and some fancy port forwarding trickery. For most of our purposes, we’ll only need to manipulate the phone, but the next section will cover both phone and wearable manipulation.


Mounting your phone to ADB

  1. Plug in phone to USB 2.0 port on your computer
  2. Open a new Terminal session
  3. In terminal navigate to {your_DL_target_folder}/android-sdk-macosx/platform-tools
  4. Type the following
 ./adb devices

This should return a list of devices attached to your computer along with their device IDs
                       
    
Congratulations! Your phone is successfully mounted to an ADB session. The next bit talks about mounting your wearable to ADB

Mounting your Wearable to ADB
There are actually a couple of ways to do this. The simplest (and least prone to error) is to plug the device directly into the computer via USB, at which point, it will simply appear in the list after running "./adb devices" in terminal. 

In the event that the watch doesn’t have a USB port, or you’re some sort of masochist, you can connect via Bluetooth by doing the following (which comes from here):

1. Enable Bluetooth debugging on the phone
On the phone, open the Android Wear companion app.
Tap the Settings icon.
Enable Debugging over Bluetooth. A status message appears under the option. It looks like this:

Host: disconnected
Target: connected

At this point the development machine (the host) is not communicating with with the watch (the target). You need to complete the link. 

2. Connect the debugger to the watch
In this final step, you'll use everything: the debugger, the phone, and the watch.

3. Connect the phone to your development machine with a USB cable.
Run these two commands in terminal:

adb forward tcp:4444 localabstract:/adb-hub
adb connect 127.0.0.1:4444

Note: You must use the IP address 127.0.0.1. You can use any available port on your development machine. Be sure you use the same port in both commands. (In this example the port is 4444.)

4. After you type the connect command, look at the watch. It will ask you to confirm that you are allowing ADB Debugging.

5. Go back to the phone and check the status display in the Android Wear companion app. It should look like this:

Host: connected
Target: connected

The watch is now connected to the debugger and you're ready to start debugging.

When you debug a watch using Bluetooth, adb always uses the IP address 127.0.0.1 plus the port that you assigned. Therefore, all adb commands use this format (continuing the example, the port is 4444):

adb -s 127.0.0.1:4444 <command> 

If you are not using the emulator and have only one device connected for debugging, you don't need to specify the address at all:

adb <command>

Setting Up New Devices

The following settings/apps should be changed/installed when setting up a new device for Android Wear testing:

New Phones --

  1. Log in to the device with our test user (email: ustwoweartest@gmail.com; pw: wearteam)
  2. Change the phone to allow for “Developer” options.
  3. In the developer menu, select: “Keep Awake”. This will allow the device to stay awake while it’s plugged into USB
  4. In the developer menu, select: “Allow USB debugging.” This will allow the device to be read by ADB.
  5. Plug the phone into USB and accept the dialog boxes which appear on the phone. Make sure to select the “Always allow from this computer” so that you don’t have to deal with this shit again.
  6. Open Google Play and download “Toolbox,” by dumplingsandwhich (They named themselves that. Don’t look at me that way.)
  7. This app will allow you to look at all of the apps on the device and give information about them, including version numbers, targeted SDKs, etc. It also has a flashlight function for some reason.
  8. Install Android Wear app
  9. Install Google Calendar
  10. Install Google Fitness app

New Wearable Devices --

  1. Follow steps for pairing the device
  2. Enable developer options on the device.
  3. In developer options, select (enable):
    • ADB Debugging
    • Debug over Bluetooth

Gotchas

Never set time forward during testing. The data layer takes the most-recent time stamp for any activity added to it and calls that “truth”. Moving time back to current time will cause any new information added to the data layer to be “false” since it has an “older” timestamp.

Outro


This is just the beginning of your journey to testing and setting up your Android Wear device. If you have any questions about testing the platform, reach out to our team at dev.nyc@ustwo.com