Running and Debugging Your Android Application On a Remote Android Device

From RAD Studio
Jump to: navigation, search

Go Up to Android Mobile Application Development


This page describes how to debug an Android application on a network-connected Android device. This method is also known as ADB over network or TCP/IP debugging. Be sure to first read Android Mobile Application Development and understand the steps needed to set up and use an Android device for development.

Some advantages of this method are:

  • Wireless connection to the Android device, no USB cable needed (for non-rooted devices you need the USB cable to change the debugging mode).
  • Simplifies the sharing of an Android device for debugging between developers.
Note: All the ADB commands on this page work if you have only one Android device connected to your machine. If you have more than one Android device connected, see Android Help: Directing Commands for a correct way to run ADB commands.
Note: Android applications always continue running in the background, although they may not be visible to users. Because the application keeps running, it may appear that the debugger itself has hung even though it has simply disconnected from the application.

Enabling TCP/IP Debugging on the Android Device

Requirements

  • The Android device has to be connected to a wireless network that is (a part of) the same as the one that your development machine is connected to.

If your Android device is not rooted, you also need:

  • A machine with Android SDK installed.
  • A USB cable.
  • The Android device to be recognized as an ADB device on machine.

If your Android device is rooted, you need:

  • Any of the following:
    • A menu setting that enables the TCP/IP debugging mode. (Available on some ROMs. Usually it is in the "Developer settings" menu. It may be called ADB over network).
    • A terminal emulator application installed on your device (such as Terminal Emulator for Android).
    • An application that enables the TCP/IP debugging mode (such as ADB over network).
Note: Your development machine can be connected to the network either wirelessly or via an Ethernet cable, as long as it is on the same network as the Android device.

Steps

If your Android device is not rooted:

  1. Connect the Android device to the machine via a USB cable.
  2. Open a terminal, such as cmd.exe.
  3. Go to the platform-tools folder of your Android SDK:
    cd "C:\Users\Public\Documents\Embarcadero\Studio\23.0\CatalogRepository\<Android SDK folder>\platform-tools"
  4. Run the following command:
    adb tcpip 5555
    Note: Replace 5555 with the port on which the device will listen for incoming connections.
  5. If you wish, you may disconnect the Android device from the machine after you run this command.

If your Android device is rooted, do any of the following to enable the TCP/IP debugging mode:

  • Enable the TCP/IP debugging mode in the "Developer settings" menu on your device (it may be called ADB over network).
  • Run the following code in a terminal emulator:
    su
    setprop service.adb.tcp.port 5555
    stop adbd
    start adbd
  • Use an application that enables the TCP/IP debugging.

Connecting to the Android Device

To connect to the Android device from your development machine, run the following command in the "platform-tools" directory of your Android SDK installation: adb connect <IPAddress>:<portNumber> (for example: adb connect 192.168.1.110:5555). <IPAddress> is the IP address of your device. These are several ways how to find the IP address of your device, such as:

  • Check in the menu of your device (usually: Settings > Wi-Fi > Advanced Wi-Fi, but may differ depending on your device OS version or manufacturer).
  • Run the following command in the "platform-tools" directory of your Android SDK installation: adb shell netcfg. This requires that your device is connected via a USB cable.
  • Find the IP address of your device in the settings page of your network router.

If the connection is successful, the command window displays: "connected to <IPAddress>:<portNumber>". You can use the command adb devices to display a list of connected ADB devices. The connected Android device should now appear on the Projects Window.

Disconnecting from a Remote Android Device

If you wish to disconnect from the Android device, you may simply reset the debugging mode on the device. Alternatively, you can run the following code on your development machine: adb disconnect <IPAddress>:<portNumber>.

Resetting the Debugging Mode on the Android Device

The debugging mode on an Android device resets every time the device is restarted. If you wish to reset the debugging mode without restarting the device, do one of the following:

  • Run the adb usb command on the remote machine to which the Android device is connected via a USB cable.
  • Run the following code in a terminal emulator on the device:
  • su
    setprop service.adb.tcp.port -1
    stop adbd
    start adbd
    

See Also