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 startup 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.
1 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):
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
Android Wear Emulation
Create an Android Wear AVD configuration as shown.
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.
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.
We need the device configured with adb debugging, and both Wear emulator and the device show up in adb devices list:
Finally, we need to forward tcp ports with,
1 > 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.
Detailed instructions for creating Wear apps can be found at:https://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,
1> 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,
1 > adb -s emulator-5554 shell pm list packages | grep example
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,
1 > adb -s emulator-5554 shell monkey -p com.example.android.uamp -c android.intent.category.L
We now have the sample app running on the Wear emulator device.
Android TV Emulation
Create an Android TV emulator configuration (AVD) as shown.
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
1 > adb -s emulator-55xx install -r mobile\build\outputs\apk\mobile-debug.apk
Finally, start the app on the Android TV emulator instance using,
1 > adb -s emulator-55xx shell monkey -p com.example.android.uamp -c android.intent.category
The sample app running on the Android TV emulator instance:
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.
Here is the universal sample app running on all 3 (TV, Phone, and Wear) along with their CPU utilizations (notice the low CPU overhead):
Developers can tweak memory allocation for further optimization. We have barely scratched the surface of emulator features in this article. Please refer to https://developer.android.com/tools/help/emulator.html for all the available config options.
For more such Android resources and tools from Intel, please visit the Intel® Developer Zone
Other Popular Deals
- The 10 best job hunting apps on AndroidTop 10 Android launchers (June 2017)
- The 10 scariest horror games on AndroidAndroid app stores: 5 best alternatives to Google Play Store
- Best Android apps for rooted devices18 apps for a memorable Valentine's Day
- Top 15 Android games that you should playThe 20 best looking games for mobile phones
- 8 Android apps to tickle your funny bone17 must have apps for any Android device (plus alternatives)
- 5 apps to get the Android Lollipop look on your smartphoneTake control of your Android device with these apps
- 7 weird and strange apps for your Smartphone10 neat Google apps you may not know of
- Perfect Viewer10 essential Indian apps for Android devices