Previous  | Next  | Home

Installing on a Device


 

To debug programs on actual hardware you must declare the application to be debuggable in the Android manifest, configure both the phone and the development computer for hardware debugging, connect the phone to the development computer with a USB cable, and transfer the executable to the device from the development computer. We first describe how to configure for debugging, and then how to transfer the executables.

 

Configuring for Debugging on Actual Devices

We summarize the basics; a more extensive discussion may be found in the Android Setting up a Device for Development document.

  1. Configuring the phone may be somewhat device-specific but here are two representative examples: On both the T-Mobile HTC G1 and the AT&T Motorola Backflip, choose Menu > Settings > Applications > Development and enable the USB debugging option. The following figure illustrates for a Motorola Backflip phone.




    We have also checked "Stay awake" to cause the screen to stay on while the phone is charging on the USB cable; it is generally useful in debugging for the screen to stay on.


  2. Connect the device to your development computer with a USB cable appropriate for the device. If you get the display in the following figure,


    you can select Charge Only unless you intend to manually transfer files to or from the device SD card: Eclipse or the ADB bridge will still load executables to the phone and execute them with this mode selected.

  3. Declare the application to be "debuggable" in the Android manifest in one of two ways:

  4. Configuration of the development computer depends on the operating system:

  5. To verify that your device is connected after the above steps, issue at a shell prompt adb devices (where adb is in the tools subdirectory of the SDK: we are assuming that you added this directory to your path earlier). Your device should appear in the list of devices that this command produces. For example, on my Fedora Linux system a typical result would be
    
      [guidry@m33 ~]$ adb devices
      List of devices attached
      TA5380467L      device
      emulator-5554   device
    
    
    In this output, emulator-5554 is the Simple2.2 emulator for Android 2.2 that we configured earlier (5554 is the port number associated with the virtual device) and TA5380467L is a Motorola Backflip phone that was connected to the computer according to the above instructions

Now that we have the device connected to the computer, we can install Android packages that we have developed and debug directly on the phone. Let's see how to do that.

 

Installing and Debugging Applications on the Device

To install an application on a physical device connected to your development computer by a USB cable as described above, you have two options:

Android requires that all applications installed on physical devices be digitally signed by the developer. If you deploy apps for 3rd-party installation through the channels such as the Android Market you must sign them with your own digital signature, but in development and debugging using Eclipse this isn't necessary because "under the hood" a debug certificate associated with the development machine is used automatically. If you debug on a device using a particular computer, the app will be installed using the debug certificate associated with that machine. If you leave the app installed and then attempt to debug the same device on a different computer you will get an error message in the logcat stream that the application signatures do not match. For example,


[2010-06-08 10:34:06 - MapTutorial] Installing MapTutorial.apk...
[2010-06-08 10:34:08 - MapTutorial] Re-installation failed due to different application signatures.
[2010-06-08 10:34:08 - MapTutorial] You must perform a full uninstall of the application. 
                       WARNING: This will remove the application data!
[2010-06-08 10:34:08 - MapTutorial] Please execute 'adb uninstall com.lightcone.maptutorial' in a shell.
[2010-06-08 10:34:08 - MapTutorial] Launch canceled!

In this case, use the uninstall command described below first to remove the application from the device, and then repeat the install as described above.


In some cases when you try to install an application on a device that has the app installed already with a different signature, Eclipse may simply not do anything, and fail to issue the error message indicating the signature mismatch. In that case, if you are certain that the device is connected properly, you should uninstall as described below and then repeat the install.

 

Uninstalling Applications from the Device

To uninstall an application resident on a physical device connected by USB:

  1. Issue from the command line of a shell adb devices to get a list of currently-running devices and their serial numbers.

  2. Issue the command adb -s <serialNumber> uninstall appname, where <serialNumber> is the serial number for the device and appname is the fully qualified name of the app package. For example,
  3. 
    [guidry@m33 ~]$ adb devices
    List of devices attached
    TA5380467L      device
    emulator-5554   device
    
    [guidry@m33 ~]$ adb -s TA5380467L uninstall com.lightcone.recipes
    Success
    
    If you know there is only a single device running, you can shorten the above to adb -d uninstall appname (the -d flag targets the only physical device running). For example,
    
    [guidry@m33 workspaceAndroid]$ adb -d uninstall com.lightcone.recipes
    Success
    
    (This returns an error if more than one physical device is running.)

In rare cases, the uninstall command may return a "Failure" flag, indicating that the uninstall has not succeeded. If your are certain that the device is connected properly to the computer, you will then have to uninstall the application manually from the device. The procedure will depend on the device, but will likely be similar to that for the Motorola Backflip: Menu > Settings > Applications > Manage Applications, then select the application, displaying its details, and press Uninstall. Consult the user documentation for your particular device if a procedure similar to this does not work. Note: Some devices may have an option to open the app list by pressing MENU, and then drag an app's icon to the trash to remove it. This may not be a reliable way to remove apps. Use the procedures given above instead.


Previous  | Next  | Home