Android ADB Setup

From Texas Instruments Wiki
Jump to: navigation, search

ADB Android Debugger & Downloader

Android Debug Bridge (adb) is a versatile tool lets you manage the state of the Android-powered device. For more information about what is possible with adb, see Android Debug Bridge page at http://developer.android.com/guide/developing/tools/adb.html. The ADB tool can be used to

  • Download an application from a host machine, install & run it on the target board.
  • Start a remote shell in the target instance.
  • Debug applications running on the device using the debugging tool DDMS ( Dalvik Debug Monitor Server) which runs on top of adb connection.
  • Copy files to and from the board to host machine

Downloading "ADB" & Host setup

The adb tool is a part of Android SDK package located at http://developer.android.com/sdk/index.html. For an overview of how to install and set up the Android SDK, follow download & setup instructions from http://developer.android.com/sdk/index.html. Once you install Android SDK, the directory contents look like the following. Note that the exact contents would vary depending on SDK version and the SDK components which are installed:

  .
  |-- SDK Readme.txt
  |-- add-ons
  |-- google-market_licensing
  |-- platform-tools
  |   |-- aapt
  |   |-- adb
  |   |-- aidl
  |   |-- api
  |   |-- dexdump
  |   |-- dx
  |   |-- fastboot
  |   |-- lib
  |   |-- llvm-rs-cc
  |   |-- NOTICE.txt
  |   |-- renderscript
  |   `-- source.properties
  |-- platforms
  |-- temp
  `-- tools
      |-- adb_has_moved.txt
      |-- android
      |-- ant
      |-- apkbuilder
      |-- apps
      |-- ddms
      |-- dmtracedump
      |-- draw9patch
      |-- emulator
      |-- emulator-arm
      |-- emulator-x86
      |-- etc1tool
      |-- hierarchyviewer
      |-- hprof-conv
      |-- lib
      |-- lint
      |-- mksdcard
      |-- monitor
      |-- monkeyrunner
      |-- NOTICE.txt
      |-- proguard
      |-- source.properties
      |-- sqlite3
      |-- support
      |-- systrace
      |-- templates
      |-- traceview
      `-- zipalign

The adb tool is located in paltform-tools/ directory under the Android SDK installation. Export the platform-tools and tools directory path as shown below.

  $ export PATH=<android_sdk_path>/platform-tools/:<android_sdk_path>/tools/:$PATH

Connecting Host machine & board through adb

The TI Android DevKit has been tested for the following methods of connecting a given board with host machine

  • adb over USB
  • adb over Ethernet

The below sections describe each of these methods and provides necessary instructions for the same.

adb over USB

  • Make sure that the mini-usb cable is connected between the host usb port and the target’s USB OTG port
  • Turn on "USB Debugging" on your board. On the board (UI screen)-
    • Go to home screen, press MENU,
    • Select Applications, select Development, then enable USB debugging.
    • Alternatively, you can navigate to Settings->Applications->Development and then enable the "USB debugging" option.
  • Setup host machine to detect the board. On Ubuntu Linux host machines this is done by adding a rules file to configure device vendor ID of on-board OMAP device.
/* For the EVMs and Boards covered here, the vendor ID is "18d1".
Note: For pandaboard, the vendor ID is "0451". */
 
/* Log in as root and create this file: */
# vim /etc/udev/rules.d/51-android.rules

/* For Gusty/Hardy, add following lines to file, save & exit */
SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"
SUBSYSTEM=="usb", SYSFS{idVendor}=="0451", MODE="0666"

/* For Dapper, add following lines to file, save & exit */
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="18d1", MODE="0666"
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0451", MODE="0666"

/* Execute the following to change the user mode for the rules file */
# chmod a+r /etc/udev/rules.d/51-android.rules

/* Verify the adb connectivity between host and target board */
# adb devices 

If device is connected, then output on screen should list the device, example:

List of devices attached
20100720    device

adb over Ethernet

  • Make sure Ethernet port on board and host machine are connected to the network
  • Check Ethernet configuration for the board
    target #> netcfg                                                                        
       lo       UP    127.0.0.1       255.0.0.0       0x00000049                       
       eth0     UP    172.24.190.59   255.255.252.0   0x00001043                       
  • If Ethernet was not configured, configure Ethernet of the board using ifconfig/netcfg as shown below.
    target #> netcfg eth0 dhcp
  • Configure the ADB Daemon to use an ethernet connection using setprop as shown below.
    target #> setprop service.adb.tcp.port 5555


  • If network is configured successfully (above steps) then Restart service adbd on the target,
    target #> stop adbd
    target #> start adbd
  • On the host machine use following commands to establish adb connection
    $> export ADBHOST=<target's ip address>
    $> adb kill-server
    $> adb start-server
  • Verify for device connectivity, by executing the following commands
    $> adb devices If connected, you'll see the device name listed as a "emulator"
    $> adb devices
    If connected, find the device name listed as a "emulator"
    List of devices attached
    emulator-5554    device
    $ adb shell 

For more information about adb commands, see Android Debug Bridge page at http://developer.android.com/guide/developing/tools/adb.html

adb over USB on Windows Machine

Follow the below instructions to get ADB over USB work on a Windows PC

  • Download latest Android SDK

(http://developer.android.com/sdk/index.html) and uncompress it in a local folder (i.e. c:\android_sdk).

  • Optionally, you may want to add the location of the SDK's primary tools directory to your system PATH. Right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the tools\ directory to the path.
  • Download Android USB Driver

(https://dl-ssl.google.com/android/repository/usb_driver_r03-windows.zip) and uncompress it in a local folder (i.e. c:\android_sdk\usb_driver)

  • Edit (or create and then edit if it doesn't already exist) file in

"%USERPROFILE%\.android\adb_usb.ini":

  echo 0x18D1 > "%USERPROFILE%\.android\adb_usb.ini"
  • Edit android_winusb.inf to match EVM/Beagle vendor and product ids:

Under [Google.NTx86] section add:

  ;TI EVM
  %SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_9018
  %CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_9018&MI_01
  ;TI AM45xEVM
  %SingleAdbInterface%        = USB_Install, USB\VID_451&PID_9018
  %CompositeAdbInterface%     = USB_Install, USB\VID_451&PID_9018&MI_01

Note: Be careful to add it under Google.NTx86 and not under Google.NTamd64 unless your machine is AMD 64 bits. If you skip this step you won't be able to later install the driver as windows will reject it.

  • Boot the board as normal and wait until shell prompt is available (micro-B USB cable must be disconnected).
  • Connect micro-B USB cable between board and Windows PC.
  • If it is proceeding as planned, Windows will tell you it found a new hardware asks you to install the driver. Install driver that was downloaded as described in step 3 above:

Answer "No, not this time" to the question about running Windows Update to search for software.

    • Choose "Install the hardware that I manually select from a list (Advanced)" this is the 2nd option, then click "Next"
    • Select "Show All Devices", then click "Next"
    • You are going to see a grayed-out text box with "(Retrieving a list of all devices)", click the "Have Disk..." button
    • Browse" to your driver folder (c:\android_sdk\usb_driver). It will be looking of a .inf file so select "android_winusb.inf" and click "Open" then "OK". It's the only file there so you shouldn't go wrong.
    • Select "Android ADB Interface" then click the "Next" button.
    • A warning will appear, answer "Yes" but read the warning anyway.
    • Click the "Close" when the wizard is completed.
  • Disconnect and reconnect micro-B USB cable from Board(probably reboot it as well).
  • Open command prompt and restart adb server just to make sure it is in a proper state:
  adb kill-server
  adb start-server
  • List the attached devices with "adb devices". It should show your board/device with a random number.
  • Type "adb shell". You should see the "#" indicating it works.

Running Applications

The root File System provided in this DevKit releases contains only standard Android components and applications. User might be interested to download & run android applications (.apk) available in the market. The below procedure gives the steps to be followed to download any .apk file to the board and run it on the platform.

Installing (.apk files) application on Target Platform

  • From the host: You can use adb tool for package installation.
    $> adb install <package>.apk. 
    

NOTE: Use -s option with the adb tool, to install the package on external storage.

On successful installation adb tool will report SUCCESS on host terminal, and the application would be listed on the android main menu.

Un-installing applications (.apk) using adb

  • To un-install non-default components (that were installed later)
    • Method 1: On the host machine execute the following
    $> adb uninstall <package>.apk
    • Method 2: On target:
    Main menu -> Menu -> Settings -> Applications -> Manage applications -> Find the package 
    Tap on it -> Uninstall -> OK -> OK
    • On successful removal, the application would have been removed from the android main menu. All the short-cuts to the application also removed.
  • To un-install default components, use the following commands from abd on host machine
    $ adb shell
    #rm /system/app/app.apk

On successful removal, the application would have been removed from the android main menu.

Setup ADB for application Debugging

ADB and Eclipse, with ADT( Android Development Tools plug-in) allow users to create and debug Android applications. Follow Developing In Eclipse, with ADT at http://developer.android.com/guide/developing/eclipse-adt.html

Steps to connect Eclipse to the board.

  • Setup the adb connection with the board by following the instructions given above in connecting board ...
    Verify the connectivity by executing 
    $ adb devices
  • Open Eclipse IDE. Eclipse, with ADT plugin enable users to
    • Create an android project.
    • Build and Run the project on a connected board.
    • Debug the project using the Debug perspective.
    • Use DDMS (Dalvik Debug Monitor Server) to monitor the connected board.

For more detailed and complete information on the above follow Developing In Eclipse, with ADT at http://developer.android.com/guide/developing/eclipse-adt.html

  • Open DDMS(Dalvik Debug Monitor Server) perspective. This DDMS perspective can be opened from the eclipse menu via:
    Window -> Open Perspective -> Other -> DDMS; 
    Click on OK
  • DDMS provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information,incoming call and SMS spoofing, location data spoofing, and more.

Copy any files to and from the board over ADB

  • Using the adb commands "pull" and "push" user can copy files to and from the board.
  • Unlike the install command, which only copies an .apk file to a specific location, the pull and push commands let you copy arbitrary directories and files to any location on the board.
  • To copy a file or directory (recursively) from the board, use
    adb pull <remote> <local>
  • To copy a file or directory (recursively) to the board, use
    adb push <local> <remote>

In the commands, <local> and <remote> refer to the paths to the file or directory on your development host (local) and on the target instance (remote).

    Here's an example: 
    adb push foo.txt /sdcard/foo.txt