Testing Android Applications on a Physical Kindle Fire Device

From Techotopia
Revision as of 14:57, 16 May 2013 by Neil (Talk | contribs)

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 much 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 both AVD emulators 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 in either 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

Enabling ADB on the Kindle Fire Device

Before ADB can connect to a Kindle Fire device, that device must first be configured to allow the connection. On the first generation Kindle Fire device this is enabled by default. On all other Kindle Fire models, go to the device settings screen, select Security and set Enable ADB to On.


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 whether the development system is running Windows, Mac OS X or Linux. Note that the following steps assume that the Android SDK platform-tools directory is included in the operating system PATH environment variable as described in the chapter entitled Setting up a Kindle Fire Android Development Environment.

Mac OS X Kindle Fire ADB Configuration

In order to configure the ADB on a Mac OS X system, connect the device to the computer system using a USB cable, open a terminal window and execute the following command:

android update adb

Next, 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 *

Once the server is successfully running with the new settings, 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, try logging out and then back in to the Mac OS X desktop and, if the problem persists, rebooting the system.

Windows Kindle Fire ADB Configuration

When a Kindle Fire with ADB support disabled is attached to a Windows system it is configured as a Portable Device. In order for the device to connect to ADB it must be configured as an Android ADB Composite Device.

First, connect the Kindle Fire device to the computer system if it is not currently connected. Next, display the Control Panel and select Device Manager. In the resulting dialog, check for a category entitled Portable Devices. Unfold this category and check to see if the Kindle Fire device is listed. In the event that it is listed, right-click on it and select Uninstall from the menu. Once the device drivers have been uninstalled, disconnect the device from the computer.

Next, open a Command Prompt window and change directory using the following command (where <sdk location> is the path to the location where the SDK was installed in Setting up a Kindle Fire Android Development Environment):

cd <sdk location>\extras\amazon\kindle_fire_usb_driver

Having changed directory, execute the following command:

KindleDrivers

After a short delay, the Kindle Fire USB Drivers Setup tool will appear as shown in Figure 6-1:


Installing the Windows Kindle Fire USB drivers

Figure 6-1


Verify that the default Destination Folder is acceptable before clicking on the Install button to initiate the driver installation process. The installation wizard will subsequently perform the driver installation. Once the installation is complete, click Finish in the wizard dialog then close the setup window.

With the drivers installed, attach the device to the computer. Open the Control Panel, change the Category menu to large icons and click on the Device Manager entry. In the device manager, there will be an entry listed as Kindle Fire which, when unfolded, will list Android Composite ADB Interface:


The Kindle Fire device listed in the Windows Device Manager

Figure 6-2


Within the Command Prompt window, 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. In the event that the device is not listed, try executing the following command:

android update adb

It may also be necessary to reboot the system.

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.

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 003: ID 1949:0006 Lab126
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

The device we are interested in is the one listed as Lab126, which is the name of the Amazon.com group originally set up to develop hardware devices. Make a note of the vendor and product ID numbers (in the above case these are 1949 and 0006 respectively). 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 and product IDs returned previously by the lsusb command:

SUBSYSTEM=="usb", ATTR{idVendor}=="1949", ATTRS{idProduct}=="0006", MODE="0660", OWNER="root", GROUP="androidadb", SYMLINK+="android%n"

Once the entry has been added, save the file and exit from the editor. 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

The final task is to create the androidadb user group and add your user account to it. To achieve this, execute the following commands making sure to replace <user name> with your Ubuntu user account name:

sudo addgroup --system androidadb
sudo adduser <username> androidadb

Once the above changes have been made, reboot the Ubuntu system. Once the system has restarted, open a Terminal window, start the adb server and check the list of attached devices:

$ 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, right-click on the KindleTest entry in the left 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:

[2013-01-07 13:32:01 - KindleTest] ------------------------------
[2013-01-07 13:32:01 - KindleTest] Android Launch!
[2013-01-07 13:32:01 - KindleTest] adb is running normally.
[2013-01-07 13:32:01 - KindleTest] Performing com.example.kindletest.KindleTestActivity activity launch
[2013-01-07 13:32:01 - KindleTest] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2013-01-07 13:32:05 - KindleTest] Uploading KindleTest.apk onto device '74CE000600000001'
[2013-01-07 13:32:05 - KindleTest] Installing KindleTest.apk...
[2013-01-07 13:32:06 - KindleTest] Success!
[2013-01-07 13:32:06 - KindleTest] Starting activity com.example.kindletest.KindleTestActivity on device 74CE000600000001
[2013-01-07 13:32:06 - KindleTest] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.kindletest/.KindleTestActivity }

Note that the Console panel has a number of modes consisting of Android, DDMS and OpenGL Trace View. If no output is displayed in the console it may be that it is not currently in Android mode. To change the mode, click on the console toolbar button as illustrated in Figure 6-3 and select Android from the drop down menu.


The Eclipse Android Console Panel

Figure 6-3


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 to 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 configure this, right-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 to Always prompt to pick device as illustrated in Figure 6-4:


Selecting an Android Run Target

Figure 6-4


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


Kindle fire android device chooser.png

Figure 6-5


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 load applications directly 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