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.
We summarize the basics; a more extensive discussion may be found in the Android Setting up a Device for Development document.
![]() |
| 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. |
![]() |
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".Mapper" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
| The selection of debuggable=true from the user interface in option (a) automatically makes this insertion in the AndroidManifest.xml file. |
SUBSYSTEM=="usb", SYSFS{idVendor}=="22b8", MODE="0666"
where 22b8 is the vendor ID for Motorola (table of vendor IDs)
SUBSYSTEM=="usb", SYSFS{idVendor}=="04e8", MODE="0666"
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"
[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 instructionsNow 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.
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. |
To uninstall an application resident on a physical device connected by USB:
[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. |