Testing Android Applications on a Physical Kindle Fire Device

From Techotopia
Jump to: navigation, search
PreviousTable of ContentsNext
Creating an Example Kindle Fire Android ApplicationAn Overview of the Kindle Fire Android Architecture


<google>BUY_KINDLE_FIRE</google>


Whilst there is much that can be achieved by testing applications using an Android Virtual Device (AVD) there is no substitute for performing real world application testing on a physical Kindle Fire device.

Communication with both AVD instances and connected Android devices such as the Kindle Fire is handled by the Android Debug Bridge (adb). In this chapter we will work through the steps to configure the adb environment to enable application testing on a Kindle Fire device on Mac OS X, Windows and Linux based systems.


Contents


An Overview of the Android Debug Bridge (adb)

The primary purpose of the adb is to facilitate interaction between the development system and AVDs and physical Android devices for the purposes of running and debugging applications.

The adb consists of a client, a server process running in the background on the development system and a daemon background process running either in AVDs or physical Android devices such as the Kindle Fire.

The adb client can take a variety of forms. For example, a client is provided in the form of a command-line tool named adb located in the Android SDK platform-tools sub-directory. Similarly, the Eclipse ADT Plugin also has a built in client.

A variety of tasks may be performed using the adb command-line tool. For example, a listing of currently active virtual or physical devices may be obtained using the devices command-line argument. The following command output indicates the presence of an AVD on the system but no physical devices:

$ adb devices
List of devices attached
emulator-5554   device

Configuring the adb to Detect a Kindle Fire Device

Testing applications on a Kindle Fire device is, unfortunately, not simply a case of connecting the device to a computer using a suitable USB cable. Instead, the adb environment must first be configured with the appropriate settings to detect the device when it is connected. Whilst this is a relatively straightforward process, the steps involved differ depending on the whether the development system is running Windows, Mac OS X or Linux.


Mac OS X Kindle Fire adb Configuration

In order to configure the adb on a Mac OS X system, begin by loading the following file into an appropriate editing tool:

~/.android/adb_usb.ini

Once loaded into an editor, add the following two lines before saving the file:

0x1949
0x0006

Having added the two lines, restart the adb server by issuing the following commands in a terminal window:

$ adb kill-server
$ adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *

In the event that the following error message is reported by the adb server, edit the adb_usb.ini file once again and make sure that there is no extra empty line after the 0x0006 line entry:

ADB server didn't ACK
* failed to start daemon *

Once the server is successfully running with the new settings, attach a Kindle Fire device to the system using a USB cable and, once connected, run the following command to verify that the device has been detected:

$ adb devices
List of devices attached
74CE000600000001        device

In the event that the device is not listed, verify that the adb_usb.ini file contains the correct entries before logging out and then back into the Mac OS X desktop and, if necessary, killing and restarting the adb server.

Windows Kindle Fire adb Configuration

The configuration of adb on Windows to recognize a connected Kindle Fire device is also a multi-step process. Before working through these steps, however, begin by connecting your Kindle Fire device to a USB port on the Windows system.

Configuring the adb_usb.ini File

Once the device is connected, the first step is to edit the C:\Users\<user_login>\.android\adb_usb.ini file (where <user_login> is replaced by your login name). Open the file using the Notepad editor and add a line that contains the value 0x1949 so that the file reads as follows:

# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x1949

Save the file and exit from Notepad.

Configuring the Google USB Driver Package

The next step is to modify the Google USB Driver package. Locate the Notepad application in the desktop start menu, right click on it and select Run as Administrator from the resulting menu.

Within Notepad open the android_winusb.inf file which will be located in the following folder (unless you opted to install the Android SDK in another location):

C:\Program Files (x86)\Android\android-sdk\extras\google\usb_driver

Modify the file to add the following lines immediately after both the [Google.NTx86] section and the [Google.NTamd64] sections of the file:

;Kindle Fire
%SingleAdbInterface% = USB_Install, USB\VID_1949&PID_0006
%CompositeAdbInterface% = USB_Install, USB\VID_1949&PID_0006&MI_01

Save the file before exiting from Notepad.

Installing the Google USB Device Driver

All that remains before starting the adb service is to install the Google USB device driver. The steps to achieve this are as follows:

1. Invoke the Windows start menu, right click on the Computer entry and select Manage from the popup menu.

2. Within the computer management tool navigate to the Device Manager category listed under Computer Management in the left hand panel.

3. In the main panel, right click on the Kindle entry located beneath the Other devices category and select Update Driver Software from the menu.

4. In the driver update dialog select the option to Browse my computer for driver software and navigate to the following folder (or the equivalent location if you installed the Android SDK elsewhere):

C:\Program Files (x86)\Android\android-sdk\extras\google\usb_driver

5. Click Next to install the device driver.

Once the driver has been installed, the device manager will contain a new Android Phone category listed as Android Composite ADB Interface as illustrated in Figure 5-1:


Kindle Fire listed in Windows device manager

Figure 5-1


Restarting the adb Server

Open a Command Prompt window and execute the following commands to restart the adb server:

adb kill-server
adb start-server

Finally, verify that the Kindle Fire device has been detected:

adb devices
List of devices attached
74CE000600000001        device

As long as the device is listed the environment is ready to test applications on the actual Kindle Fire device.

Linux Kindle Fire adb Configuration

For the purposes of this chapter we will once again use Ubuntu Linux as a reference example in terms of configuring adb on Linux to connect to a physical Kindle Fire device for application testing.

Identifying the Linux USB Device

Begin by attaching the Kindle Fire device to a USB port on the Ubuntu Linux system. Once connected, open a Terminal window and execute the Linux lsusb command to list currently available USB devices:

~$ lsusb
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 003: ID 1949:0006 Lab126

The device we are interested in is the one listed as Lab123 which, as mentioned in a previous chapter, was the name of the Amazon.com group originally set up to develop hardware devices. Make a note of the vendor ID number (in the above case this is 1949).

Editing the 51-android.rules File

Use the sudo command to edit the 51-android.rules file located in the /etc/udev/rules.d directory. For example:

sudo gedit  /etc/udev/rules.d/51-android.rules

Within the editor, add the appropriate entry for the Kindle Fire device, referencing the vendor ID returned previously by the lsusb command:

SUBSYSTEM=="usb", SYSFS{idVendor}=="1949", MODE="0666"

Once the entry has been added, save the file and exit from the editor.

Modifying the adb_usb.ini File

Next, use an editor to modify (or create if it does not yet exist) the adb_usb.ini file:

gedit  ~/.android/adb_usb.ini

Once the file is loaded into the editor, add the following lines before saving the file and exiting:

0x1949
0x0006

Restarting the adb Server

The final step is to restart the adb server and verify that the Kindle Fire is visible to adb:

$ adb kill-server
$ adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
$ adb devices
List of devices attached
74CE000600000001        device

Testing the adb Connection

Assuming that the adb configuration has been successful on your chosen development platform the next step is to try running the test application created in the chapter entitled Creating an Example Kindle Fire Android Application on the device itself. Launch Eclipse and load the KindleTest example application. Right click (or Ctrl+click on Mac OS X) on the KindleTest entry in the right hand panel and select Run As -> Android Application. If the Kindle Fire is connected and detected by adb, the application will load and run on the device instead of within the emulator. Output on the console panel should read as follows as the application is loaded:

[2012-04-05 14:33:52 - KindleTest] Android Launch!
[2012-04-05 14:33:52 - KindleTest] adb is running normally.
[2012-04-05 14:33:52 - KindleTest] Performing com.payloadmedia.kindletest.TestActivity activity launch
[2012-04-05 14:33:56 - KindleTest] Uploading KindleTest.apk onto device '74CE000600000001'
[2012-04-05 14:33:56 - KindleTest] Installing KindleTest.apk...
[2012-04-05 14:33:57 - KindleTest] Success!
[2012-04-05 14:33:57 - KindleTest] Starting activity com.payloadmedia.kindletest.TestActivity on device 74CE000600000001
[2012-04-05 14:33:58 - KindleTest] ActivityManager: Starting: Intent 
{ act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.payloadmedia.kindletest/.TestActivity }

Manual Selection of the Application Run Target

By default Eclipse and the Android ADT Plug-in are configured to automatically choose the run target for application testing. This means that when a physical Kindle Fire device is attached to the system and visible to adb the application will run on the device. In the event that the device is not connected, however, the default is run within the emulator.

It is possible, however, to configure the environment to prompt you for the target each time the application is launched from within Eclipse. To achieve this, right click or Ctrl-click on the application name (in this case KindleTest) in the right hand panel and select the Run As -> Run Configurations… menu option. Within the Run Configurations dialog, select the Target tab and change the Deployment Target Selection Mode from Automatic to Manual as illustrated in Figure 5-2:


Changing the Android test run target selection default

Figure 5-2


Click on the Apply button and then close the dialog. On future application launches, the Android Device Chooser window shown in Figure 5 3 will appear providing the choice between running within the emulator or on a connected physical Kindle Fire device:


The Android device chooser with a Kindle Fire device listed

Figure 5-3

Summary

Whilst the Android Virtual Device emulator provides an excellent testing environment, it is important to keep in mind that there is no real substitute for making sure an application functions correctly on a physical Kindle Fire device. This, after all, is where the application will be used in the real world.

By default, however, the Eclipse and Android ADT environments are not configured to detect the Kindle Fire as a target testing device. It is necessary, therefore, to perform some steps in order to be able to directly load applications onto a Kindle Fire from within the Android development environment. The exact steps to achieve this goal differ depending on the development platform being used. In this chapter we have covered those steps for Linux, Mac OS X and Windows based platforms.


<google>BUY_KINDLE_FIRE</google>



PreviousTable of ContentsNext
Creating an Example Kindle Fire Android ApplicationAn Overview of the Kindle Fire Android Architecture