Talking to localhost from inside an Android emulator
March 03, 2026 [Programming, Android, Tech]If you're developing an Android application that talks to a server, you may well
want to run the server locally and talk to it from your Android emulator. If you
point at localhost, this means the Android device itself, not the server
running on your computer.
There is various information about how to make this work online, but the only reliable way I have found is to run a command like this on the command line:
adb reverse tcp:8000 tcp:8000
(With thanks to this StackOverflow answer.)
This command makes http://localhost:8000 on the Android device point at
http://localhost:8000 on your computer, so if you are running a server on port
8000 on your computer, if you run the above command, you can talk to the server
from the Android emulator using this URL.