Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to a local server from an android emulator?

Started a local server in my computer with IP 127.0.0.1 listening on port 3000.

However, I am unable to access it via my android app when I run the emulator on android studio. I got a timeout error from my app's networking library, so it is not making connection.

like image 878
XYseven Avatar asked Jul 29 '16 23:07

XYseven


People also ask

Can I access localhost from Android Emulator?

If you're using Android Studio to run the emulator, then localhost of your host computer will be mapped to the IP address, 10.0. 2.2 , inside the emulator. If you're using other programs to run the emulator, then you may need to consult the documentation associated with those programs.


2 Answers

Use the IP address 10.0.2.2. You can read more at here.

like image 113
Singh Avatar answered Oct 13 '22 22:10

Singh


On each Android emulator Android Studio runs a router for it in order to isolate the emulated device from your development system. Thus in order to access a local server running on your development system (your laptop, desktop, etc) you must use the special IP of 10.0.2.2 and the port the server is listening on. To learn more read this page.

like image 27
JWhit Avatar answered Oct 13 '22 23:10

JWhit