Sean Barbeau
Sean Barbeau

Reputation: 11756

How to set up ADB for remote machine development and local device deployment

My scenario is this: I telework from home and log into my work machine via Windows Remote Desktop. I use Eclipse as my development environment for Android apps on my work computer.

Using ADB, I would like to be able to deploy apps from my work computer to a device on my home network, for scenarios where the emulator doesn't do the app justice.

I found this post, which discusses a very similar scenario, with the exception of deploying to an emulator running on a local PC, instead of deploying to a local device:

Android: ADB remote emulator access

I'm trying to take the same steps, but figure out how to target a local device on my home Wi-Fi network and tethered to my local home PC, instead of the local emulator.

Right now, I have the remote PC set up to try and connect to my public router IP address on port 5585, but in my router, what IP address/port do I forward this to to connect to the local device?

In the example using the emulator, they forward to the local PC address where the emulator is running and port 5555, and ADB is not running on the local PC. I have configured my router to forward to my device IP address, with the device on Wi-Fi, as well as my local PC IP address where the device is tethered.

However in both scenarios, when I try adb connect <router_IP_address>:5585 on my remote PC, it gives me an error unable to connect to <router_IP_address>:5585:5585. I get the same response when trying to forward to/listen to other ports. I'm not getting any security errors in the router log, so it appears the port forwarding is working.

Questions:

Upvotes: 54

Views: 84263

Answers (7)

hannes ach
hannes ach

Reputation: 17763

This is how I made it work from the host macOS with the emulator to the macOS client.

A: One line command

On the host of the emulator

socat tcp-l:5560 tcp:localhost:5559

On the client

adb connect <IP address>:5560

B: With a tunnel

On the host

adb kill-server
adb -a nodaemon server

On the client

adb kill-server
ssh -L 5037:localhost:5037 <host IP address>

Open a second shell on the client

adb kill-server  # I observe first it kills the client ADB
adb kill-server  # Then it kills the server ADB. Do it maybe once more
adb devices      # Show devices on the server now

Now I see the host emulator in Android Studio as well:

Enter image description here

Upvotes: 5

Pakkes
Pakkes

Reputation: 49

Probably there is a simpler solution, provided the device, the local, and the remote machine belong to the same network.

Let's say your device has a certain IP address over the network and let's say you decide to use your preferred port: Well, you can do the following steps.

On the machine where the device is plugged in, please run:

adb devices

adb tcpip <PORT>

An example of PORT is 5555.

On the remote machine, you need to deactivate 'Discover USB devices', 'Discover network targets' and 'Port forwarding'. And then run:

adb connect IP_ADDRESS:PORT

IP_ADDRESS is your Android device IP address (not the first machine's IP address) which you can get from adb shell ip -f inet addr.

And you are ready to debug on the remote machine.

Upvotes: 4

Jindor
Jindor

Reputation: 430

Another setup for remote host + local device testing. This will be useful for lots of people working from home on a laptop, connected to their development host machine still in the office. Note that I assume both development host/laptop are both running Unix, but other OSes will be able to run the commands on the command prompt/shell.

On the development host

# Kill the old ADB server.
adb kill-server

On the laptop

# Activate ADB server on the client
adb start-server

# Start an SSH tunnel. Hide/minimize this window to not close it by accident
ssh -XC -R 5037:localhost:5037 <your development host machine>

On the development host

# It should work by now with the local device connected to the laptop
adb logcat

Upvotes: 14

Bugmonster
Bugmonster

Reputation: 21

My situation required using a VM that is on a different network, but that I rmd into (an Azure VM). The VM and my local laptop are both running Windows 10. First, I had to install USB Redirector RDP Edition on my local machine (costs US$80, but there might be free alternatives), then install the Google Android USB driver on the VM and the Universal ADB Driver on the VM. I'm now able to load the project in Android Studio on the VM, connect an Android device on my laptop, and debug the app on the device.

Upvotes: 2

Guy Chauliac
Guy Chauliac

Reputation: 650

I had a similar situation. I work on a remote desktop for development, but my Android device is connected to my local laptop. I wanted to be able to use ADB and the Android plugin in Eclipse on the remote desktop and connect to the device attached to my laptop. After searching on the Internet and not finding anything that really helped, I decided to write a port forwarder that would do the trick. You can find it here.

Upvotes: 51

Uma sankar pradhan
Uma sankar pradhan

Reputation: 419

You can solve the issue by port forwarding.

  • Download Secure Shell app from the Chrome app store
  • Connect to your machine (step-by-step setup)
  • In this connection, disable adb server: adb kill-server
  • Create a new port forwarding connection (same as a regular connection, but set the SSH Arguments field to: -N -R 5037:localhost:5037)
  • On your laptop, open up a terminal and enable adb server: adb start-server

Upvotes: 5

Roman Saveljev
Roman Saveljev

Reputation: 2594

Beginning Android 4.3 you can:

  1. Make adb server listen on all interfaces. You have two options:
    • Make gListen=1 and recompile adb (I have compiled it on Linux-x64 machine for you and put it here)
    • Start adb server with -a parameter: adb -a -P 5037 fork-server server&
  2. Use adb on your remote machine with extra parameter, e.g. adb -H <remote_host> shell

Upvotes: 27

Related Questions