Simple Guidance For You In Connecting Android Emulator To Localhost

It’s a minor problem but it can cause headaches, connecting Android emulator to localhost is one of the important things we should...

· 2 min read >

It’s a minor problem but it can cause headaches, connecting Android emulator to localhost is one of the important things we should care about.

By default, the Android emulator will automatically recognize as localhost so it is easy to develop API on a local machine.

But what if it doesn’t work that way? Hmm.. a lot of people struggling to find a way to connect to localhost

Using Default IP

The native solution is much better than using a third-party application, and here is the easiest way to use the default IP.

The key is to start localhost using on our localhost server, then on the emulator. And don’t forget to use the same port both localhost and emulator.

  • Start localhost by using and NOT localhost;
  • Use on your API URL inside your project
  • Use the same port for both URL
Another story  How To Host Multiple Domain In One Droplet In DigitalOcean VPS

Let’s the image below tell us more 😀 we can use the native PHP Server command to start localhost php -S -t public. If you use Lumen framework, don’t forget to add “public” as an entry directory.

Android emulator connected to localhost

If you want the other ways, there are several third-party software that can be used such as ngrok. By ngrok, you can connect the emulator as well as real devices to localhost.


Ngrok provides a real-time web UI where you can introspect all HTTP traffic running over your tunnels. Replay any request against your tunnel with one click.

You can run ngrok by typing ngrok http 80 in console or terminal. For Mac user, we used dot back-slash before ngrok command such as ./ngrok http 8800 or using optional parameter region, ./ngrok http 8800 -region=us for US or ./ngrok HTTP 8800 -region=ap for the Asia Pacific. Use your own port to connect.

Another story  How To Manage My Amazon Ebooks On Kindle And iPhone Better In Less Time

I think this software is very useful if we want to show progress to the client. By providing Ngrok Url, we can test mobile app to real devices if we don’t have any server deployed yet.

Due to heavy traffic, ngrok can sometimes be very slow. You should purchase a premium service for better network handling and customization.
Squidman app and Ngrok

Another option is to use a special proxy to match your local port or use Squidman app proxy.


Squidman can be powerful for testing the responsiveness of websites as well as local APIs for development on real devices.

But this couldn’t be easier due to the lack of documentation. Of course, it will be an interesting challenge for us. Connecting Android emulator to localhost will also be easy and tricky.

Another story  Rest API Tutorial Php: Creating Standalone And Simple API For Beginner

Maybe next time, I will write another story about using this Squidman application, because I have also used this software to test the responsiveness of the website directly to the mobile device browser, it gives me a nice feeling and exciting experience.

What if the emulator can’t connect to internet?

Another issue about connecting Android emulator to localhost is that it can’t connect to the internet. But it’s about your DNS or internet provider issue. This has nothing to do with the things we discussed earlier.

The emulator sometimes needs to connect to the internet if we are using a network image for example, so the internet is an issue.

We have to switch to another network or try to use Google public DNS, but I prefer the first solution by bringing my portable modem 😀 and switching the laptop network to this modem.

2 Replies to “Simple Guidance For You In Connecting Android Emulator To Localhost”

  1. Everything is very open with a precise clarification of the challenges. It was really informative. Your website is useful. Thanks for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *

Right Menu Icon