Tutorial

Pair your android phone emulator to android wear emulator with android studio

Noräs Salman Noräs Salman |

Tags: #ADB #Android #Android Studio #Android wear #Emulator #Wear OS

Whether you started thinking about making your first android wear aka ( Wear OS ) application or already have been doing it for a while. Being able to use the tools that Google provides with their powerful Android Studio IDE saves quite some time while developing you apps.

Android studio provides the ability to test your android applications on emulators, not only for phones but also for wear devices. A problem arise when trying to interact between different emulators. For example there is no direct way or option available to connect android phone emulator with an android wear emulator running on the same host (computer).

During my journey making my first android wear app, and after researching a while I was able to find a way, or a small hack to make it work.

Step 1: Locating your SDK tools path

Have you worked with ADB before? Can you access the ADB command from your terminal/command prompt? Then you can skip this step.
 
  • Star by opening you Android studio.
  • In the menu bar go to Tools > Android > SDK Manager.
  • Star by opening you Android studio.
  • Identify the path by looking at the “Android SDK Location”.

Fire up your terminal or command prompt and change the working directory to the path found i.e the (Android SDK Location). Run the command adb and make sure it’s working.

Instead of navigating to the SDK tools directory every time, you can skip doing that by adding the path to your bash profile on Mac/Linux or to your environmental variables on Windows.

Extra:On Mac and Linux

Edit your bash profile with your favorite editor. Personally I like nano for fast tasks.

nano ~/.bash_profile

Add the following line to with replacing YOUR_Android_SDK_Location_HERE including the asterisks symboles with the path you found.

export PATH=${PATH}:***YOUR_Android_SDK_Location_HERE****

Example:

export PATH=${PATH}:/Users/noras/Library/Android/sdk/platform-tools
Extra:Windows

Add the path to the environmental variable.

Step 2: Setup your emulators

Make sure you have both a Phone emulator and a Wear OS emulator. Make sure that your phone emulator API level is compatible with the Wear OS version.

Boot up both emulators and install the Android Wear/Wear OS app on the phone emulator, run the application and then go through the terms until you reach the screen that says not connected on the action bar.

From ADB check that both are listed.

nindoda:~ noras$ adb devices
List of devices attached
emulator-5556	device
emulator-5554	device

Step 3: Connect the emulators

Telnet to your phone emulator (5556) is the phone emulator port. You can see that on the emulator window title bar.

nindoda:~ noras$ telnet localhost 5556

It will tell you that authentication is required.

Android Console: Authentication required
Android Console: type 'auth <auth_token>' to authenticate
Android Console: you can find your <auth_token> in 
'/Users/noras/.emulator_console_auth_token'

Copy your authentication token (Open new terminal window).

nindoda:~ noras$ cat '/Users/noras/.emulator_console_auth_token'
XXXXXXXXX

Go back to the old window with (telenet) and authenticate.

auth XXXXXXXXX

Redirect the traffic and port forward.

redir add tcp:5601:5601

Congratulations

You have successfully connected the two emulators. It should say connected on the android wear application on the phone emulator. If you have a android wear app that sends data to your phone, or vise versa you should be able to trigger these events now.


About the author

Noräs Salman

"Senior Software Engineer. MSc in Computer systems and Networks with big interest in security. Loves to play with Android code and does security research for fun and profit. Speaks 4 languages and codes in much more."

Related articles

Tags: #ADB #Android #Android Studio #Android wear #Emulator #Wear OS




Copyright © 2019 - nindoda.com