- Android Wearable Programming
- Steven F. Daniel
- 804字
- 2021-07-16 13:31:43
Setting up an Android development environment
In this section, we are going to look at the key concepts to get you started with Android Wear development. Google recommends using Android Studio for development, because of the tight integration it has with the Wear development APIs, as well as the streamlined build cycle with Gradle, that helps minimize a lot of the manual configuration that the developer would need to do in other IDEs.
Before you begin, and as a prerequisite to starting to work with Android Studio, you will need to ensure that your system has the latest version of the Java Runtime Environment (JRE) installed for the version of the operating system that you are using.
Note
To determine if your system has the JRE or the Java Development Kit (JDK) installed, open a new terminal window and issue the following command from the command line:
java –version
Once you have determined if you have Java installed, you can proceed to download Android Studio for your version of the operating system. The Android Studio package can be downloaded from the Android developer tools web page at http://developer.android.com/sdk/installing/studio.html.
Android Studio for Windows systems can be downloaded from https://dl.google.com/dl/android/studio/install/1.2.2.0/android-studio-bundle-141.1980579-windows.exe.
Android Studio for Mac OS X systems can be downloaded from https://dl.google.com/dl/android/studio/install/1.2.2.0/android-studio-ide-141.1980579-mac.dmg.
Android Studio for Linux systems can be downloaded from https://dl.google.com/dl/android/studio/ide-zips/1.2.2.0/android-studio-ide-141.1980579-linux.zip.
Now that you have downloaded and installed Android Studio, you can begin installing the Android 4.4W (API 20) for your system:
- Launch Android SDK Manager by using the SDK Manager in Android to download API level 20 (4.4 KitKat Wear).
- Select and click on the Android 4.4W.2 (API 20) package:
You will notice that we have chosen to install the Android Wear system images for both ARM and Intel. Intel delivers greater performance while running your app using the Android Emulator, but you can select the appropriate one for your chipset. If you decide to install both, the Android Studio IDE at design time will inform you which one is supported.
In the next section, we will need to install the Android Wear support libraries for our Android Wear application that will allow your Android wearable app to target a specific version of the Android SDK APIs.
Installing the Android Wear support library
The Android Wear support library contains a set of numerous code libraries that allow you to target a specific version of the Android SDK APIs. Each library contains a different set of features that can help to improve the look of your application, and with the release of Android 5.0 you can incorporate Material design as well as add support for rich notification features.
The benefit of using the latest Android Wear support libraries is that it allows your applications to take advantage of the new and improved features for devices that are running Android 5.0 and above. However, while your app can still run on devices running Android 1.6 and above, some features will not be available:
Scroll down to the Extras
folder, and select the Android Support Library, as shown in the preceding screenshot. Next, click on the Install packages button as shown in the preceding screenshot.
If you are using Android Studio for your Android Wear development, this can provide you with a much easier and more convenient way of adding the Android Wear support library to your existing applications. Android Studio uses a module model, where the mobile and wear modules are part of a single project.
Setting up and configuring the Android (AVD) Emulator
In our next step, we will need to set up and configure our Android Wear Emulator. This will allow us to test our Android Wear apps that we will be developing throughout this book.
Open your Android Virtual Device (AVD) manager and create a new virtual device for your Android Wear, as shown in the following screenshot:
Before we end this section, it is worth mentioning that while Android Emulator is the most powerful and convenient tool that you will use throughout your development of Android apps, it is important for developers to understand the types of limitations it comes with, which are explained in the following points:
- The Android Emulator simulates real handheld device behavior, but not specific hardware implementations
- Sensor information, such as satellite location, battery, and power settings, as well as network connectivity, is all simulated using your computer
- Access to the camera hardware is not fully functional
- There is no ability to place or receive phone calls, or send SMS messages, as these are all simulated
- There is no support for USB available
As you can see, using the Android emulator is not recommended as a substitute for testing your apps on a true handset or device. Now that we have set up all of the preliminary configurations, we can start to build our Android Wear application.