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
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.
And the Android Virtual image versions are,
My Emulator configurations are:
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.
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 220.127.116.111840.
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:
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.
Looking at the window head of your Phone emulator, you can identify the port on which your emulator is running.
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.
Open the Android Wear companion app on your Phone emulator
Then, click on the Watch-like icon (next to Emulator – Not Connected) to get connected to your Android Wear emulator device.
Look at the Watch emulator, and Voila!
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!