# Troubleshooting ADB connections to Starnix

This page provides troubleshooting tips for making an ADB connection to Fuchsia
devices.

## Install the adb tool

To use `ffx starnix adb` commands, you must have the `adb` tool installed on
your host machine.

To install the `adb` tool:

- **Linux (Debian-based)**: Run the following command:

      sudo apt install adb

- **Other platforms** : Download the [Android SDK Platform-Tools](https://developer.android.com/tools/releases/platform-tools)
  and ensure the `adb` binary is in your `PATH`.

## Forwarding ADB ports

If you cannot use the `adb` command to connect to your Fuchsia device over USB,
you can connect to an Android instance running inside Starnix using TCP port
forwarding:

1. In one terminal, forward a host port to the device's ADB port (`5555`):

       ffx forward "HOST_PORT=>5555"

   Replace `HOST_PORT` with an available port on your machine
   (for example, `5559`).

   > [!TIP]
   > **Tip:** You can also run this `ffx forward` command in the background with the `-q` (quiet) flag, for example: `ffx forward -q "5559=>5555" &`.

2. In a second terminal, connect the ADB server to that host port:

       adb connect localhost:HOST_PORT

However, there are a few ways this setup can fail to work, and this page
includes guidance for addressing common issues.

## Make an ADB connection to an emulator

For making an ADB connection to the Fuchsia emulator (FEMU), you can run the
following command instead:

    ffx starnix adb connect

This command enables `adb` to connect to your Fuchsia emulator using TCP and
makes use of a network address provided by `ffx` for the connection.

## Multiple adb devices

When multiple Android devices are connected to your development machine or when
the Android device is running in an emulator, you may see an error from `adb`
that multiple devices are present and it doesn't know which one to use.

To verify if your development machine's ADB server sees multiple devices,
run the following command:

    adb devices -l

If the output lists multiple devices, you need to specify a target device for
your `adb` commands. The identifier for the device connected via port forwarding
is the address you used in the `adb connect` command (for example,
`localhost:5559`).

You can pass this identifier as an argument to your `adb` commands using the
`-s` flag, for example:

    adb -s localhost:HOST_PORT shell ls

Alternatively, you can set it as the `ANDROID_SERIAL` environment variable,
which will be used by subsequent `adb` commands:

    export ANDROID_SERIAL=localhost:HOST_PORT

Once this environment variable is set, you can use `adb` commands normally.
[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/development/starnix/troubleshooting_ffx_starnix_adb_connect.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/development/starnix/troubleshooting_ffx_starnix_adb_connect.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/development/starnix/troubleshooting_ffx_starnix_adb_connect.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/development/starnix/troubleshooting_ffx_starnix_adb_connect.md "Edit the source code of this page")