16

I've started android emulator app and trying to open from embeded browser locally started web-site, but local dns name (from /etc/hosts) is not resolved. Is there any option to enable local resolving?

Alexey Poimtsev
  • 2,845
  • 3
  • 35
  • 63

3 Answers3

18

Refer this URL. The issue is 127.0.0.1 is not the correct IP for accessing local server sites on emulator.

http://localhost:8080/MyTestPage.html // URL to use in computer browser
http://10.0.2.2:8080/MyTestPage.html  // URL to use in emulator browser

However, you need to do some configuration changes as suggested in the URL.

TheCottonSilk
  • 8,662
  • 2
  • 26
  • 37
10

Here's how to access a locally hosted website in the Android emulator.

  1. Use IIS/Apache to host the application.
    For some obscure reason, Android Virtual Device would not let you connect to the development server created by Visual Studio.

  2. Once you host the application, use your IP address as the web address to connect to the local website. "localhost" just won't work with the AVD. Just go to the command prompt and type ipconfig to get your local ip address. You should be looking for IPv4 Address

Here's Android AVD connecting to Apache (XAMPP)

https://drag2up.appspot.com/Z6xc

Here's connecting to IIS

alt text

Good Luck everyone and happy testing!!

Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
  • Using Android Studio, this worked for me on both a Genymotion and an AVD emulator; having my project hosted either on my computer or my virtual host, However it's weird it's not working with 10.0.2.2:8080. Many people insist that's the correct address. – Juan José Melero Gómez Jun 12 '15 at 22:09
3

You should specify your local ip address in browser, something like 192.168.xx.xx

Fedor
  • 43,261
  • 10
  • 79
  • 89
  • i have dev. site on 127.0.0.1 - tried with domain name and ip 127.0.0.1 - emulator does not resolving any of both. – Alexey Poimtsev Jul 14 '10 at 18:41
  • it looks like emulator uses preconfigured dns server and ignoring any local sites :( – Alexey Poimtsev Jul 14 '10 at 18:42
  • Exactly. I also hav dev site on 127.0.0.1. Emulator can't connect to 127.0.0.1. That's why I just specify my local ip like that 192.168.xx.xx. This way emulator connects to my dev site correctly. – Fedor Jul 14 '10 at 23:17
  • 1
    What about when you use virtual hosts to map different development sites? Any way to just edit the hosts file? – tonyhb Aug 24 '11 at 10:01
  • You have to set up IP-based virtual hosts instead of name-based. – Eric Z Beard Nov 26 '11 at 16:05