# Connect to ADB

ADB is a communication protocol specific to Android that allows to connect or control an Android device from a computer.

It can be used with a Genymotion Device image instance for:

  • controlling an instance Android OS
  • connecting an instance to a developer's tool (IDE), such as Android Studio, VS Code, JetBrains Rider, etc.
  • accessing an instance shell
  • uploading files to an instance

# Pre-requisites

Google's Android SDK platform-tools from https://developer.android.com/studio/#command-tools (opens new window) or Android Studio.

Note

The Android SDK platform-tools are included with Android Studio. By default, they are located in the following folders:

  • Linux: /home/your_username/Android/Sdk
  • macos: /Users/your_username/Library/Android/sdk
  • Windows: %AppData%\Local\Android\Sdk

# Enable or disable ADB

Warning

When enabling ADB, your instance becomes accessible using the standard 5555 TCP port. Since the ADB connection is neither secured nor authenticated, we strongly recommend to only open TCP port 5555 to specific hosts in your Security Group and/or EC2 Firewall.
Alternatively, we recommend using an SSH tunnel to secure the connection.

You can then connect the instance to ADB:

adb connect {instance_public_IP}

# Use an SSH tunnel

Note

It is assumed that you have already read the Accessing a virtual device from SSH chapter.

# 1. Create an ssh tunnel

# 2. Connect ADB to the instance

  1. Open another shell to run other commands.
  2. Connect your virtual device to ADB:
adb connect localhost:5555

To connect other virtual devices to ADB, make sure you increment the port number for every new virtual device (e.g. 5556, 5557, 5558, etc.). For example:

ssh -i key.pem -NL 5556:localhost:5555 [email protected]{instance2_public_ip}

Then, to connect this instance to ADB:

adb connect localhost:5556