Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Setting up Development Environment for Android Wear Applications

Save for later
  • 8 min read
  • 16 Nov 2016

article-image

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe."

-Abraham Lincoln

In this article by Siddique Hameed, author of the book, Mastering Android Wear Application Development, they have discussed the steps, topics and process involved in setting up the development environment using Android Studio. If you have been doing Android application development using Android Studio, some of the items discussed here might already be familiar to you. However, there are some Android Wear platform specific items that may be of interest to you.

(For more resources related to this topic, see here.)

Android Studio

Android Studio Integrated Development Environment (IDE) is based on IntelliJ IDEA platform. If you had done Java development using IntelliJ IDEA platform, you'll be feeling at home working with Android Studio IDE.

Android Studio platform comes bundled with all the necessary tools and libraries needed for Android application development. If this is the first time you are setting up Android Studio on your development system, please make sure that you have satisfied all the requirements before installation. Please refer developer site (http://developer.android.com/sdk/index.html#Requirements) for checking on the items needed for the operating system of your choice.

Please note that you need at least JDK version 7 installed on your machine for Android Studio to work. You can verify your JDK's version that by typing following commands shown in the following terminal window:

setting-development-environment-android-wear-applications-img-0

If your system does not meet that requirement, please upgrade it using the method that is specific to your operating system.

Installation

Android Studio platform includes Android Studio IDE, SDK Tools, Google API Libraries and systems images needed for Android application development.

setting-development-environment-android-wear-applications-img-1

Visit the http://developer.android.com/sdk/index.html URL for downloading Android Studio for your corresponding operating system and following the installation instruction.

Git and GitHub

Git is a distributed version control system that is used widely for open-source projects. We'll be using Git for sample code and sample projects as we go along the way.

Please make sure that you have Git installed on your system by typing the command as shown in the following a terminal window.

setting-development-environment-android-wear-applications-img-2

If you don't have it installed, please download and install it using this link for your corresponding operating system by visting https://git-scm.com/downloads.

If you are working on Apple's Macintosh OS like El Capitan or Yosemite or Linux distributions like Ubuntu, Kubuntu or Mint, chances are you already have Git installed on it.

GitHub (http://github.com) is a free and popular hosting service for Git based open-source projects. They make checking out and contributing to open-source projects easier than ever. Sign up with GitHub for a free account if you don't have an account already.

We don't need to be an expert on Git for doing Android application development. But, we do need to be familiar with basic usages of Git commands for working with the project.

Android Studio comes by default with Git and GitHub integration. It helps importing sample code from Google's GitHub repository and helps you learn by checking out various application code samples.

Gradle

Android application development uses Gradle (http://gradle.org/)as the build system. It is used to build, test, run and package the apps for running and testing Android applications.

Gradle is declarative and uses convention over configuration for build settings and configurations. It manages all the library dependencies for compiling and building the code artifacts.

Fortunately, Android Studio abstracts most of the common Gradle tasks and operations needed for development. However, there may be some cases where having some extra knowledge on Gradle would be very helpful. We won't be digging into Gradle now, we'll be discussing about it as and when needed during the course of our journey.

Android SDK packages

When you install Android Studio, it doesn't include all the Android SDK packages that are needed for development. The Android SDK separates tools, platforms and other components & libraries into packages that can be downloaded, as needed using the Android SDK Manager. Before we start creating an application, we need to add some required packages into the Android SDK.

Launch SDK Manager from Android Studio Tools | Android | SDK Manager.

setting-development-environment-android-wear-applications-img-3

Let's quickly go over a few items from what's displayed in the preceding screenshot.

As you can see, the Android SDK's location is /opt/android-sdk on my machine, it may very well be different on your machine depending on what you selected during Android Studio installation setup. The important point to note is that the Android SDK is installed on a different location than the Android Studio's path (/Applications/Android Studio.app/).

This is considered a good practice because the Android SDK installation can be unaffected depending on a new installation or upgrade of Android Studio or vice versa.

On the SDK Platforms tab, select some recent Android SDK versions like Android 6.0, 5.1.1, and 5.0.1.

Depending on the Android versions you are planning on supporting in your wearable apps, you can select other older Android versions.

Checking on Show Package Details option on the bottom right, the SDK Manager will show all the packages that will be installed for a given Android SDK version.

setting-development-environment-android-wear-applications-img-4

To be on the safer side, select all the packages. As you may have noticed already Android Wear ARM and Intel system images are included in the package selection.

Now when you click on SDK Tools tab, please make sure the following items are selected:

  • Android SDK Build Tools
  • Android SDK Tools 24.4.1 (Latest version)
  • Android SDK Platform-Tools
  • Android Support Repository, rev 25 (Latest version)
  • Android Support Library, rev 23.1.1 (Latest version)
  • Google Play services, rev 29 (Latest version)
  • Google Repository, rev 24 (Latest version)
  • Intel X86 Emulator Accelerator (HAXM installer), rev 6.0.1 (Latest version)
  • Documentation for Android SDK (Optional)

setting-development-environment-android-wear-applications-img-5

Please do not change anything on SDK Update Sites. Keep the update sites as it was configured by default.

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime

Clicking on OK will take some time downloading and installing all the components and packages selected.

Android Virtual Device

Android Virtual Devices will enable us to test the code using Android Emulators. It lets us pick and choose various Android system target versions and form factors needed for testing.

Launch Android Virtual Device Manager from Tools | Android | AVD Manager

From Android Virtual Device Manager window, click on Create New Virtual Device button on the bottom left and proceed to the next screen and select Wear category

setting-development-environment-android-wear-applications-img-6

Select Marshmallow API Level 23 on x86 and everything else as default, as shown in the following screenshot:

setting-development-environment-android-wear-applications-img-7

Note that the current latest Android version is Marshmallow of API level 23 at the time of this writing. It may or may not be the latest version while you are reading this article. Feel free to select the latest version that is available during that time.

Also, if you'd like to support or test in earlier Android versions, please feel free to do so in that screen.

setting-development-environment-android-wear-applications-img-8

After the virtual device is selected successfully, you should see that listed on the Android Virtual Devices list as show in the following screenshot:

setting-development-environment-android-wear-applications-img-9

Although it's not required to use real Android Wear device during development, sometimes it may be convenient and faster developing it in a real physical device.

Let's build a skeleton App

Since we have all the components and configurations needed for building wearable app, let's build a skeleton app and test out what we have so far.

From Android Studio's Quick Start menu, click on Import an Android code sample tab:

setting-development-environment-android-wear-applications-img-10

Select the Skeleton Wearable App from Wearable category as shown in following screenshot:

setting-development-environment-android-wear-applications-img-11

Click Next and select your preferred project location.

As you can see the skeleton project is cloned from Google's sample code repository from GitHub.

setting-development-environment-android-wear-applications-img-12

Clicking on Finish button will pull the source code and Android Studio will compile and build the code and get it ready for execution.

The following screenshot indicates that the Gradle build finished successfully without any errors. Click on Run configuration to run the app:

setting-development-environment-android-wear-applications-img-13

When the app starts running, Android Studio will prompt us to select the deployment targets, we can select the emulator we created earlier and click OK.

setting-development-environment-android-wear-applications-img-14

After the code compiles and uploaded to the emulator, the main activity of the Skeleton App will be launched as shown below:

setting-development-environment-android-wear-applications-img-15

Clicking on SHOW NOTIFICATION will show the notification as below:

setting-development-environment-android-wear-applications-img-16

Clicking on START TIMER will start the timer and run for five seconds and clicking on Finish Activity will close the activity take the emulator to the home screen.

setting-development-environment-android-wear-applications-img-17

Summary

We discussed the process involved in setting up the Android Studio development environment by covering the installation instruction, requirements and SDK tools, packages and other components needed for Android Wear development.

We also checked out source code for Skeleton Wearable App from Google's sample code repository and successfully ran and tested it on Android device emulator.

Resources for Article:


Further resources on this subject: