Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Android

Using Intel® HAXM for Developing Android Wear and TV Apps

0.00/5 (No votes)
6 Jul 2015CPOL5 min read 10.3K  
We will look at how developers can take advantage of the Intel HAXM emulator when developing a universal Android app that targets different Android platforms like Android Wear and TV, and device variations.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Intel® Developer Zone offers tools and how-to information for cross-platform app development, platform and technology information, code samples, and peer expertise to help developers innovate and succeed. Join our communities for Android, Internet of Things, Intel® RealSense™ Technology and Windows to download tools, access dev kits, share ideas with like-minded developers, and participate in hackathon’s, contests, roadshows, and local events.

Android* has come a long way initially starting with phones, then tablets, Google TV*, Android Wear*, Android TV* (replaces Google TV), and Android Auto*. It can be challenging for developers to build and test their apps to run on all these device types. Add to this different device form factors and display resolutions, and it can quickly become a complex app verification and testing problem. We have Intel® HAXM to the rescue.

Intel® Hardware Accelerated Execution Manager (HAXM) is a hardware-assisted Android emulator with low-overhead, excellent performance, and low latency. You can learn more about it here: https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager

With Intel HAXM, developers can have multiple Android emulator instances running on their development system without having to worry too much about performance, load or latency issues. This can be very helpful in the iterative process of app development and testing, resulting in huge developer productivity.

Non-x86 Android emulator images can have slow start-up time and sluggish UI responsiveness. Unlike some third-party Android emulators, with Intel HAXM you can use all the latest Android API versions and platforms as soon as they are released.

For detailed instructions on using Intel HAXM please see https://software.intel.com/en-us/android/articles/speeding-up-the-android-emulator-on-intel-architecture

In this blog post we will look at how developers can take advantage of the Intel HAXM emulator when developing a universal Android app that targets different Android platforms like Android Wear and TV, and device variations.

Using the Universal Android Sample App

Google recently released a sample universal app to show how developers can target multiple form factors with the same code base. Please see the following link to learn more: https://github.com/googlesamples/android-UniversalMusicPlayer

This sample app showcases some of the best practices for targeting multiple form factors with the same code base. Follow the instructions in the above link to build the app. We will be using it to load x86 HAXM Emulator instances for TV, Wear and Phone in this article.

The project can be directly imported into Android Studio* and developers can take advantage of the integrated emulator features. If you prefer to use other IDEs, the following can be helpful.

If you are comfortable with cmd line, just invoke the gradle build script from sample source directory.

gradlew assembleDebug

The apk will be available at "mobile/build/outputs/apk/mobile-debug.apk" folder.

Create the AVDs for Android TV and Wear

We need to ensure we downloaded the latest Android SDK emulator images for TV and Wear, along with the standard Android image for phone/tablet.

Open the android SDK manager. You can invoke from cmd line (<Android-SDK>/tools folder should be in your path):

> android

Image 1

​Next, we need to create the emulator configurations (AVDs) to use the above images.

Open the Android Virtual Device manager. You can invoke from cmd line

> android avd

Image 2

Android Wear Emulation

Create an Android Wear AVD configuration as shown.

Image 3

Click "OK", and start the Wear emulator by clicking "Start…" in the AVD Manager Window. A screenshot of the Wear emulator after first boot, is shown below.

Image 4

Android Wear requires a companion app to be installed on your phone. This app is only available on the Google Play store, so it requires us to have a device with access to the store.

https://play.google.com/store/apps/details?id=com.google.android.wearable.app

We need the device configured with adb debugging, and both Wear emulator and the device show up in adb devices list:

Image 5

Finally, we need to forward tcp ports with,

> adb -d forward tcp:5601 tcp:5601

The Wear emulator should now be able to connect to your device. The below screenshots show the Wear emulator in connected and disconnected states.

Image 6

Detailed instructions for creating Wear apps can be found at: http://developer.android.com/training/wearables/apps/creating.html

Like any android apk, we can manually install our sample app apk on the Wear emulator using the adb,

> adb -s emulator-5554 install -r mobile\build\outputs\apk\mobile-debug.apk

Verify that it is in fact installed and available on the Wear emulator using,

> adb -s emulator-5554 shell pm list packages | grep example

Image 7

The package name for the sample app, com.example.android.uamp is listed.

We can even manually run the sample app on the Wear emulator using,

> adb -s emulator-5554 shell monkey -p com.example.android.uamp -c android.intent.category.LAUNCHER 1

We now have the sample app running on the Wear emulator device.

Android TV Emulation

Create an Android TV emulator configuration (AVD) as shown.

Image 8

Click "OK", and start the TV emulator by clicking "Start…" in the AVD Manager Window.

We can verify if the emulator is accessible from adb using

> adb devices

Note down the emulator id (eg: emulator-55xx), which you can use as the target for adb commands. Install the apk using

> adb -s emulator-55xx install -r mobile\build\outputs\apk\mobile-debug.apk

Finally, start the app on the Android TV emulator instance using,

> adb -s emulator-55xx shell monkey -p com.example.android.uamp -c android.intent.category.LAUNCHER 1

The sample app running on the Android TV emulator instance:

Image 9

Developers can create and start as many emulator configurations/instances as needed.

Intel HAXM can be configured with appropriate memory size at installation time.

The below screenshot shows the Wear, TV and phone AVD configurations.

Image 10

Here is the universal sample app running on all 3 (TV, Phone, and Wear) along with their CPU utilizations (notice the low CPU overhead):

Image 11

Developers can tweak memory allocation for further optimization. We have barely scratched the surface of emulator features in this article. Please refer to http://developer.android.com/tools/help/emulator.html for all the available config options.

References

*Other names and brands may be claimed as the property of others

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)