Search code examples
androidandroid-studioandroid-5.0-lollipop

Access localhost, Mac Android Studio Emulator


I'm running a local http server on port 3000 and i'd like to access that server using an Android emulator. I've tried the following in the browser:

  • localhost:3000 //
  • 127.0.0.1:3000 // of course I gave my local ip a try
  • 10.0.3.2:3000 // I think this is a genymotion ip?
  • 10.0.2.2:3000 // The most prevailing suggestion was to use this ip

With each of these i'm given this error: enter image description here

Interestingly when accessing the same in chrome on my desktop:

localhost:3000 // works
127.0.0.1:3000 // doesn't work

Perhaps this is connected? I'm not sure why 127.0.0.1:3000 doesn't work, but that might be a different hurdle altogether.

My /etc/hosts file:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 

I've already tried reloading (& disabling) my firewall and proxies.

The emulator i'm using is:

Mac, Android Studio 1.5.1
Emulator : Nexus 5 - API 21, Android 5.0 x86 

Solution

  • Use following Service

    https://ngrok.com/

    It will give you a tunnel to localhost and give you a URL which you can use from anywhere in the world ;)