Android Wear is a new version of the Android system designed specifically for wearables , which was announced by Google in march 2014. Currently lots of devices running on Android Wear were released, including well designed Moto 360 and Gear Live by Samsung.But still, amount of applications using all the benefits of Android Wear in Google Play is considerably small.



In this tutorial I'm going to show you how to create apps for Android Wear from Scratch.



Set up the Android development environment

JDK – development kit for Java programming language

– development kit for Java programming language Android Studio – IDE to make our Android apps

– IDE to make our Android apps Android SDK – special development kit for Android development

– special development kit for Android development Android Virtual Device – emulator to test our apps

JDK

Studying every new technology begins with launching "Hello World" example. But first you need to set your development environment.

Android applications are usually developed in Java programming language using the Software Development Kit. That's why we need to download SDK for working with Java.



1) Download the Java SE Development Kit (JDK) from this site: http://www.oracle.com/technetwork/java/javase/downloads/

2) Click Download from the JDK section of the 'Java Platform, Standard Edition' table.

3) Install the JDK environment with default setting



You can find more detailed instruction here:

http://www.oracle.com/technetwork/java/javase/index-137561.html

Android Studio

Google developed its own environment for Android applications with lots of perks for development. You can download it here: http://developer.android.com/sdk/index.html



Here are steps for installation Android Studio on Windows and Linux. For MAC they are pretty similar.

Installation for Windows:

Installation for Linux:

1) Download and run **android-studio-bundle-(your version).exe**, then click on the "Next" button.2) Leave all default settings untouched and click the **"Next"** button.3) Agree with all license agreements and click the "Next" button.4) Choose a path where to install Android Studio and Android SDK.(**Please note**: use only ASCII characters - english letters)5) Android SDK includes Android device emulator. It means you can use emulator when you don't have Android Wear Watch. I'm going to use emulator in this tutorial. Emulator for Windows requires installation of the Intel Hardware Accelerated Execution Manager (Intel HAXM).In this window you can adjust the amount of memory avaliable for HAXM. Leave it recommended and click the "Next" button.6) Select or create a folder in which you would like to create the program's shortcut.7) Now the installation of Android Studio begins. Required time depends on your computer. For me it took about half an hour. Next click on the «Finish» button.

Download android-studio-ide-(your-version)-linux.zip. Unzip it (Please note: don't use non ASCII characters in istallation path). Open terminal, go to Android Studio folder, then go the bin folder and run studio.sh script. These steps you can see in the screenshot for my system - Ubuntu 14.10.



Android SDK

Creating new project

The start window of Android Studio should appear after the installation.(click on created shortcut if the start window did not appear(for Windows) or run script studio.sh(for Linux)). Android platform includes systems for phones, tvs and watches, so we need to download special development toolkit for Android Wear. Click onand turn onIf you want to test your applications on emulator, you also need to download virtual images, (Intel x86 images will work faster). I recommend you to download samples for SDK, we are going to study them later. If you want to test your application for different Android Wear versions, you need to download SDK and virtual image for Android 4.4. Don't change default settings (so USB driver will be installed. It maintains correct plugging a device into a computer.) Next click on "Install" button and agree with licence agreement.SDK installation can take a while(about couple of hours).

Having downloaded SDK, we move to creating your first Android Wear application. More precisely we are going to study one of the samples provided by Google.

Run Android Studio and Click Option «Import an Android code sample»





Type "Wear" in the searching box and choose "Skeleton Wearable App". Then click on the "Next" button.





Now you can choose the name and path of your project. (Please note: don't change it unless there are non ASCII characters) and click "Finish":





Wait till the project is downloaded and built.

Please notice:

If you can see the error like:

"Failed to import new Gradle project: failed to find Build Tools revision xx.xx.xx "

then you don't have the latest version of the build tool. One of the main benefits of Android Studio is that it can do menial work. Just click on "Install and sync project".

Your first project is done.

Now we need a watch to test an application. You can use an emulator if you don't have a watch.

Set up an Android Wear Virtual Device(AVD)

Click Tools>Android>AVD Manager or click on corresponding button in the panel:





Click Create Virtual Device and after that choose category Wear in List and select Square or Round Android Wear(you can see that I selected Round) and click "Next":





Choose Android Wear version(I chose Lollipop for this tutorial, because it's the latest version and most user-friendly, in my opinion.) and click "Next":





Now you can change name of your AVD (I named it Smartwatch tutorial), choice of screen or firmware. Also you can turn on Host GPU (better do it, that way the emulator will use computer video card for rendering).

You can also turn on "Store a snapshot for faster startup". It lets AVD Manager to save system state on hard disk after you finish working with emulator. It allows you to run the emulator faster, because any Android emulator runs really slow(except third-party emulators, like Genomytion)

After you finish setting click on the "Finish" button.





Emulator created successfully.





Now you can run the emulator, it can take a while. After that you can study how to work with Android Wear following instructions.







Run the app

We need to set startup configuration to run this app. Click a field left from "Run", there you can "Edit Configuration" or choose module to run.Choose "Wearable"(because we are going to run the application for watches) and click on "Run".







Now we can see the list of devices ready for the application to be installed on. Choose the emulator we created early. (you need to run the emulator first.)



After the application is started click on "Show Notification" button, and application should show you sample notifications.

You can see that this sample is not adapted for round shape of the watches. You have to avoid this while developing applications for Android Wear.



Sum up

In this tutorial we set up our system for development applications and ran our first Android Wear application.

In next tutorial I will show you how to connect your watches(or emulator) with your phone(or tablet). Please don't hesitate to ask any questions and leave feedback. Thank you for reading.

Continue to Tutorial Part 2 - Connecting AndroidWear with your mobile device