# 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, you can use an SSH tunnel to secure the connection.

Since Genymotion Device image ver. 7.0.0, ADB can be enabled or disabled from the Web UI:

  1. Go to the Configuration panel:

    Configuration screenshot

  2. In the ADB section, click on the toggle button to enable or disable ADB access:

    Enable ADB

It is also possible to do it by command line with SSH, or with our HTTP API:

Command Line (ssh)
  1. Log in with SSH or PuTTY. Please refer to Accessing a virtual device from SSH
  2. Enable or Disable ADB:
# switch to root
$ su

# enable ADB
setprop persist.sys.usb.config adb

# disable ADB
setprop persist.sys.usb.config none
HTTP API

You can use the POST method and call the /configuration/adb API to set the following variables:

  • Set active:true to enable ABD at run-time, and/or active_on_reboot:true to enable after reboot.
  • Set active:false to disable ADB at run-time, and/or active_on_reboot:false to disable after reboot.

For detailed usage, please refer to Genymotion HTTP API.

You can then connect the instance to ADB:

adb connect {instance_public_IP}

# Use an SSH tunnel

Note

It is assumed that you are familiar with Accessing a virtual device from SSH section.

# 1. Create an ssh tunnel

Note

  • key.pem is your private key and {instance_public_ip} is the public IP of your virtual device instance.
  • shell is a specific user for SSH operations - do not use a different username.

From a new terminal/shell create an SSH tunnel:

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

Important

Do not close this terminal/shell or this will close the tunnel as well.

To create a tunnel for other virtual devices, make sure you increment the port number for every new virtual device (5556, 5557, 5558, etc.) For example:

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

If you use PuTTy, you can refer to the instructions below:

With PuTTy

Windows 10

OpenSSH is now included with Windows 10 by default (see this article (opens new window)). PuTTy is no longer necessary nor recommended with Windows 10.

  1. Set PuTTy to connect to your instance.
  2. Go to Connection > SSH > Tunnels and set Source port to 5555 and Destination to localhost:5555.
  3. Click on Add.
    PuTTY tunnel setting
  4. Click on Open to start the connection.
    PuTTY tunnel save

Important

The PuTTy terminal has to remain open during your operations. If PuTTY is closed, it will close the tunnel as well.

To create a tunnel for other virtual devices, make sure you increment the port number for every new virtual device (5556, 5557, 5558, etc.)

# 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