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.

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 alibsfolder and copyclasses.jarinto thelibsfolder.

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 thewearable-1.0.0folder 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 athttps://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 whereandroid.support.wearable.view.WatchViewStubis not found.

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

This will resolved the issue earlier regarding the missing library.

There is just more one thing. Now, in your project, open yourstyles.xmland 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 athttp://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 yourDemoWearAppAndroidManifest.xml file, notice that the sample Android Wear app is using packagecom.example.demowearappand pay attention to theVersion CodeandVersion Nameas 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’scom.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 yourDemoWearAppprojectand generate the signed APK file and rename it towearable_app.apk

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

Still onDemoWearAppOnPhoneproject, create a new xml file,wearable_app_desc.xmlatres/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 bewearable_app (this will point it to the signed wear APK you put in res/raw folder earlier)

Next open the AndroidManifest.xml file forDemoWearAppOnPhoneproject.

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

Finally, double check yourDemoWearAppOnPhoneproject structure and make sure it’s like shown below:

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

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 新手如何学习SQL
  2. 2019年终总结
  3. Python数据结构:字典那些事儿
  4. 你真的了解参数估计和假设检验吗?
  5. Python数据结构:神奇的序列
  6. 遇到喷子,请先别急于反驳!
  7. 一份电商数据分析案例
  8. 怎样绘制漂亮的统计图表|不一样的折线图
  9. C#基础入门第十三天(多态接口)
  10. 【51CTO博客最全】2021阿里Java后端面试