Guide: Start an android emulator on your remote linux system

I have a light(cheap) linux laptop, I can develop on it, but it’s a lot slower(compilation+emulation) than my desktop linux pc, so I need to connect to my desktop pc to have an acceptable performance. You don’t need this if you are at home and have a monitor attached to your stronger pc. Vs Code’s remote extension starts everything on the remote machine, you just need to start the emulator manually for the remote session.

This is how you can run and view the emulator on the local machine:

Add the 1234 tcp port to your firewall.

Open the emulator on your remote machine normally from the GUI, then:

adb forward tcp:1234 tcp:5555
adb tcpip 5555
ssh -Nfg -L 1234:localhost:5555 localhost

IMPORTANT: You need to run the above commands after every adb daemon restart on your remote machine

On your local machine, connect to the emulator’s adb instance:

adb connect <REMOTE MACHINE'S IP>:1234

IMPORTANT: You need to run the connect command after every adb daemon restart on you local machine

Then you can accept the debugging request in the emulator. You should do this for every emulator, but ideally it should happen only once. Now you can close the emulator. It might be possible to accept the request from command line, but I didn’t try it, since I have a monitor on my remote machine. shell - How to accept debugging dialog for Android Emulator via command line - Stack Overflow

After this you can start the emulator for the remote session through ssh.

IMPORTANT: Use the emulator in sdk-path/emulator/ not the one in sdk-path/tools/

emulator -list-avds to see the available emulators.

You can launch a headless android emulator with this command, it works without needing to be logged into desktop environment on the remote or if you use wayland. I couldn’t figure out how to start the emulator with -gpu host through ssh if I’m logged into a wayland session.

emulator $name_of_avd -no-window

If you are logged into an X session, this way it renders on the gpu and it’s a little bit faster, not by a lot though:

DISPLAY=:0 emulator $name_of_avd -gpu host -no-window

Optionally, you can use screen to start the emulator and be able to close the terminal window after.

Then use scrcpy or Android Studio’s built-in screen mirroring to access the emulator’s display.

This should work with a windows local machine too.

You can also connect your physical android device to the remote with a vpn connection like tailscale(easiest), wireguard or openvpn+wireless debugging.