How to develop and package Android Wear App using Eclipse

Tang Tung Ai
7 min readJul 15, 2014

Google rolled out Google Play services 5.0 to all supported devices worldwide, which including Android wearable services APIs on 2nd July 2014. Since then, we start to work on an Android Wear companion app for InstaB (Social Network for new Parents) https://play.google.com/store/apps/details?id=com.iconmobi.instab

However, it took us a while to figure out how to do it using Eclipse as most of the guide provided are for Android Studio. Thanks to the helpful Android Wear Developer Communities on Google+, we finally manage to complete and launch the first simple version of InstaB companion app for Android Wear.

http://www.youtube.com/watch?v=_11DDH7eVoU

We decided to put the step by step on how to setup and package an Android Wear app using Eclipse.

First of all, we assumed that you already have Eclipse setup with the latest ADT (Android Development Tools). If not, please do so, you can find the steps here. http://developer.android.com/tools/sdk/eclipse-adt.html

Once you have the latest ADT installed, you need to download the latest Android 4.4W SDK. Start Android SDK Manager and find for Android 4.4W (API 20) and check it all and proceed to install it.

Now, before you start to create an Android Wear project, you’ll need the Android Wear Support library (android.support.wearable). To use this, you need to manually extract it out from Google Support Repository and add it to your workspace.

In order to add this to your workspace, please follow the steps below:

Go to your Android SDK folder, and find this file, ./extras/google/m2repository/com/google/android/support/wearable/1.0.0/wearable-1.0.0.aar

Copy the wearable-1.0.0.aar to a new location that you preferred. Then rename it to zip file before extracting it. After you extract it, create a libs folder and copy classes.jar into the libs folder.

Next step is to add this Android Wear Support library to your Eclipse workspace.

Create a new Android project and choose import from existing code and pick the wearable-1.0.0 folder that you’d just extracted. Remember to go to your project properties and tick the “Is Library” checkbox. And you are ready to go.

Now it’s time to create your first Android Wear project.

Create a new Android Project and follow the settings as below:

And in the Create Activity screen, choose Blank Wear Activity as below:

Important Note: If you are running on latest ADT , you might not have the wizard to create Blank Wear Activity. In this case, you need to manually import the blank wear project template to your project. This template can be downloaded at https://github.com/tangtungai/Android-Wear-Black-Activity-Template

Ok, now you had created your Android Wear project on Eclipse. But when you open your MainActivity.java, you’ll see error as below where android.support.wearable.view.WatchViewStub is not found.

Still remember the wearable-1.0.0 library that we added to workspace earlier? Now, in your Android Wear project, go to your Project properties and add this wearable-1.0.0 in as library.

This will resolved the issue earlier regarding the missing library.

There is just more one thing. Now, in your project, open your styles.xml and change your application theme to default as shown below:

and you are ready to go.

Let’s try to run your project on Android Wear Emulator

To do this, you need to setup your Android Wear Emulator. Open your Android Virtual Device (AVD) Manager and create a new Virtual Device for your Android Wear as below:

This will create a new emulator in your virtual device list. To start, just choose the emulator and click Start.

And your Android Wear emulator will look like this. You’ll notice that there is a cloud icon beside the battery icon. This cloud icon mean that your Android Wear is not paired/connected to any devices.

To connect it to your device, you will need an Android device running on Android OS 4.3+ and above. Install Android Wear app from Google Play Store. (https://play.google.com/store/apps/details?id=com.google.android.wearable.app). After that, plug-in your device using USB to your development machine and run command below:

adb -d forward tcp:5601 tcp:5601

And your Android Wear Emulator will be connected to your Android device.

Android Wear app setting on your Android devices. Notice that it show the Emulator is connected.

Notice that the cloud icon no longer shown as it already connected to your devices.

Now, lets start to run your test Android Project.

Remember to choose the Wear Emulator as target device.

And it will run successfully to show you something as below on your Wear Emulator.

So now you can start to develop your Android Wear app and debug it using emulator if you doesn’t have any wear devices. You can learn more about Android Wear SDK at http://developer.android.com/training/building-wearables.html

Now, it’s time to package your Android Wear app

After you finish developing your Android Wear app, surely you want to release it to Google Play Store. So you’ll need to package it into a normal Android App APK file because Google doesn’t allow Android Wear standalone app as the Android Wear devices cannot download app directly from Google Play Store.

This part can be a little tricky, so please be careful. ☺

First of all, open your DemoWearApp AndroidManifest.xml file, notice that the sample Android Wear app is using package com.example.demowearapp and pay attention to the Version Code and Version Name as we will need that too later.

Ok now you’ll need to create a new Project (DemoWearAppOnPhone) for your Android app that will be install on your phone. Please make sure the package name should be the same as your Android Wear app, in this sample it’s com.example.demowearapp

And choose Black Activity if you doesn’t need any activity on your this app on your phone.

Next step is very important where you’ll add in Google Play Services 5.0 to this project. (Before hand, you will need to import Google Play Services to your workspace, more info can be found here, http://developer.android.com/google/play-services/setup.html#Install)

Ok, now open back your DemoWearApp project and generate the signed APK file and rename it to wearable_app.apk

Copy this file and put it into your DemoWearAppOnPhone project at folder /DemoWearAppOnPhone/res/raw/

Still on DemoWearAppOnPhone project, create a new xml file, wearable_app_desc.xml at res/xml/ folder.

Notice that the package name should be same as your DemoWearApp project as well as the <versionCode> and <versionName>.

The value for <rawPathResId> should be wearable_app (this will point it to the signed wear APK you put in res/raw folder earlier)

Next open the AndroidManifest.xml file for DemoWearAppOnPhone project.

Add in the 2 extra meta-data block above. No changes required.

Finally, double check your DemoWearAppOnPhone project structure and make sure it’s like shown below:

And finally, what you need to do is generate a signed APK for DemoWearAppOnPhone and you are ready to release your first Android Wear app.

We hope this guide will be useful for those who wish to develop Android Wear app on Eclipse.

Cheers.

InstaB Co-Founder

November, Movember, IT’S MOUSTACHE TIME AGAIN!

Movember is an annual movement, a chance for men around the world to grow a moustache once a year without catching flack from the women in their life. ☺ To celebrate this year Movember, we going to have this Movember Droid T-Shirt for both Movember supporter as well as Android Fans.

Check it out to support at http://teespring.com/movemberdroid

Have a nice day!

--

--

Tang Tung Ai

#developer #son #husband #father #sarawakian #foochow #instabforbaby