Developing for Android Wear with Emulators

After a lot of struggle, I finally managed to connect Android Wear running as an emulator to an Android Phone, also running as an emulator. Yes, you read that right! If you don’t have a phone running Android 4.0.3 and above, and no watch either; all is not lost. You can still develop for Android Wear.

Before we go into the details of how to setup your environment, do note that these are settings that work for me and on my work laptop. It may or may not work for you. But I’ll do my best to give you as much detail as possible in the smallest of content write-up that I can. So let’s get started.

 

My Laptop configuration and details are:

Laptop Brand & Model: Lenovo T420

OS: Windows 7 Enterprise

Processor: Intel Core i7

RAM: 8GB

Graphics: Intel Integrated HD / NVIDIA NVS 4200M

 

Make sure your SDK is up to date. The version of Android SDK tools I use is 23.0.2 and for Android SDK Platform-tools is 20.

SDK_Version

And the Android Virtual image versions are,

AndroidImages_Version

 

My Emulator configurations are:

Phone Emulator:

AVD_Nexus5

Notice that I use the Google APIs virtual image instead of the Android Image. I am not sure if it would work without a Google APIs image but my guess would be no, as a lot of Android Wear relies on Google Play Services.  API Level 19 is Android KitKat 4.4.2 which satisfies the minimum required Android version for connecting to an Android Wear device.

 

Wear Emulator:

AVD_Watch

Next, you will have to install the Android Wear companion app on your Phone emulator. The version of Android Wear that works for me is 1.0.0.1261840.

AndroidWear_Version

Now, open command prompt (CTRL + R -> ‘cmd’) and change directories to ‘adt-bundle-windows-x86-2014xxxx\sdk\platform-tools’. This is where Android Debugging Bridge (adb) resides and you will need this tool to identify the list of emulators that are tied up to adb itself.

In the command prompt, run the below command:

adb devices

adb_Devices

Make sure that the adb shows two emulators in the list. If it does not, then you will have to restart the emulator that is not showing up in the list. You could alternatively try to run the below commands in order and hopefully adb will list both of them this time.

adb kill-server

adb start-server

adb devices

Looking at the window head of your Phone emulator, you can identify the port on which your emulator is running.

AVD_Nexus5_Home

My Phone emulator is currently running on port 5554.

In command prompt window, enter the below command to start a telnet session at the port of your Phone emulator

telnet localhost 5554

In the telnet session for this port, enter the below command.

redir add tcp:5601:5601

You should see an ‘OK’ output if all went well. It is important that you type in the characters carefully, as everytime you use the backspace to correct a typo, the telnet command will almost always fail.

Note that you have to set redir for tcp port 5601 every time you start your Phone’s emulator (I would prefer you run this after starting both of them). If at any point, adb loses connection with an emulator, you would be required to do these steps again for the connection to happen.

You can use the below command to list out the redir you just added. However, this step is not required.

redir list

Open the Android Wear companion app on your Phone emulator

AndroidWear_Home

Then, click on the Watch-like icon (next to Emulator – Not Connected) to get connected to your Android Wear emulator device.

AndroidWear_Connected

Look at the Watch emulator, and Voila!

Watch_Home

If for some reason the Android Wear emulator does not connect to the Phone emulator, try disconnecting and re-connecting from the Android Wear companion app on the Phone emulator. I have noticed that sometimes clicking anywhere on the Android Wear emulator (which opens the Google Voice Command screen) helps in the detection of the emulator.

Hope you have managed to set your environment with the information provided above. Do give your feedback if you manage to do so. Let me know your difficulties in the comments and I will try to resolve any issues that you face.

All the best developing for Android Wear!

Advertisements

22 thoughts on “Developing for Android Wear with Emulators

  1. I am trying above on mac, all the steps are working. But after redir tcp:5061:5061 the phone emulator goes to not-responding state.

  2. @neithal I assume you typed 5601:5601 correctly instead of 5061:5601.
    Sorry, I don’t have much clue about Mac. In Windows I would check Event manager under device administrator tools for reasons why applications crash (in our case, the android emulator).

  3. Looking at the SO link, it looks like you have a typo in your command -> E:\Program Files\Android\android-sdk\platform-tools>adb install “E:\Program File s\Android\android-sdk\platform-tools\wearable.apk”

    “Program File s” – space between ‘e’ and ‘s’

    Once your in the ~\android-sdk\platform-tools\ dir on command prompt, you do not need to specifiy full path to .apk

    Try: E:\Program Files\Android\android-sdk\platform-tools>adb install wearable.apk

  4. I’m the one having problem.

    I set up the forward but clicking on the watch icon on the emulator doesn’t connect it with the wear emulator. 😦

    1. Did you try this…
      “If for some reason the Android Wear emulator does not connect to the Phone emulator, try disconnecting and re-connecting from the Android Wear companion app on the Phone emulator. I have noticed that sometimes clicking anywhere on the Android Wear emulator (which opens the Google Voice Command screen) helps in the detection of the emulator.”

    1. Hi Phil,

      Apologies for the late reply. I’ve been busy with other work and have not explored Android Wear with MM emulator.

      I see that you got around to fixing the issue by yourself. That’s great! You could also check, if haven’t already, to see if your MM emulator has updates in the SDK manager. That way you would have proper versions of the Google App & Play Services, allowing you to install the latest (MM supported) Wear App for testing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s