9

I have two PCs. One runs Ubuntu and another runs Windows. Both have adb installed. I have an emulator on Ubuntu and I want to connect to it from Windows. I thought I could use adb forward but it doesn't work. On Ubuntu, I set up

adb forward tcp:8080 tcp:5555

adb tcpip 5555

Then, in Windows, I tried to connect:

adb connect user@ubuntu-ip-address:8080

But it cannot connect.

PS: I can connect through ssh from Windows to ubuntu and use adb normally.

1

2 Answers 2

6

Suppose you have PC1 and PC2. According to the official Android Developer documentation, adb forward is not for forwarding a TCP port of the PC1 to another port of the PC2. It's for forwarding a TCP port of PC1 to a TCP port of the Android device.

For your situation, you can use any port forwarding tool like Port Forwarding for Windows.

There is a nice tutorial below copied from hasper.info by Philipp Hasper:

I often use the Android emulator to check my apps with different display configurations and to stress-test them. But the problem is that it is really slow on my development laptop. So I installed the Android emulator on my desktop PC running Windows and connect to it over my LAN. The major advantage is that you can continue using your development machine while a “server” deals with emulating – one could even emulate several devices at once and still continue programming.

The approach in a nutshell: Forward the emulator’s port so that it is accessible in the local network. Then connect the ADB to it.

On your desktop – the “server”:

  1. Store the executable of Trivial Portforward on the desktop system (e.g. directly in C:\trivial_portforward.exe).

  2. Create a virtual device to emulate (HowTo) and name it “EmulatedAndroid”.

  3. Create a batch file:

    <your-android-sdk-path>\tools\emulator -avd EmulatedAndroid &
    echo 'On the development machine: adb kill-server and then: adb connect <desktop-pc-name>:5585'
    C:\trivial_portforward 5585 127.0.0.1 5555
    
  4. If you execute this batch file on your desktop PC, it will open the emulator with the specified virtual device.

Now on your laptop – the “client”:

  1. Now – given that both systems are in the same network – you can connect to the emulator from your laptop by typing in a terminal:

    adb kill-server
    adb connect <desktop-pc-name>:5585
    
  2. Now you can upload apps, access the logcat and execute adb commands on your remote emulator like on any other Android device. And all without performance impairments on your workstation.

  3. If you are experiencing communication losses, increase the emulator timeout in the eclipse settings to maybe 5000 ms (Window → Preferences → Android → DDMS → ADB connection time out (ms)).

3
  • I have noticed using this way, Android debugging doesn't work. it tries to connect to new port which they decide to meet using abd default communication channel. Jul 17, 2021 at 6:24
  • How to do this from a mac to an other mac ? Or from a macOS client to a Linux hosted emulator ?
    – hannes ach
    Feb 24, 2022 at 15:01
  • This almost works, except that I see that the port is restricted using Resource Monitor. After adding an exception rule in Windows Firewall, this works like a charm!
    – Mygod
    Feb 18, 2023 at 16:30
1

I just want to update answer, since approach with trivial_portforward is not easy, because issuer is not online anymore and you have to compile it. And also this page is first in google results.

Best approach for port forwarding is to use ssh. If you want to install SSH on windows,here are:

On Host:

a) nodaemon server:

host$ adb kill-server
host$ adb -a nodaemon server

b) create ssh server

Just create ssh server on host machine, if it is windows. I did it this way.

On Client:

a)

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

b)

adb kill-server
ssh -L 5585:localhost:5555 serverusername@<host-IP-or-hostname>
adb connect localhost:5585

Then authenticate. Also portforwading is possible do on host or client, if both have ssh server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .