73

I can not figure out how to access localhost from a Genymotion android emulator. By the way, Im using MAMP.

2
  • 2
    You've mis-stated the question. "localhost" is never anything but the system on which your program is running, in this case that would refer to the emulated android device itself, which can of course be accessed at the address 127.0.0.1 Likely you are looking for a way to access a service running on the system hosting the emulator instead. Nov 28, 2013 at 3:39
  • Ahm thanks for the comment. What i am aiming is that, i want to access the 'localhost:8888' in my computer, which is running MAMP, from a Genymotion android emulator. Is that possible?
    – mownier
    Nov 28, 2013 at 3:57

10 Answers 10

180

Update

After genymotion update to 2.2 you can use 10.0.3.2, ref

Another approach

To access your localhost through Genymotion is using your PC IP address. to get your IP address go to:

start -> cmd -> ipconfig

then search for IPv4, copy the IP and paste it in your URL. It should looks like the following:

String YourURL = "http://192.168.0.106:8888/your_script_location.php";

Hope this works too for you, give me a feedback.

P.S: if it didn't work, turn off the firewall and any anti-virus application you have in your PC.

4
  • 3
    10.0.3.2 didn't work (connection refused) but the address given by Virtual Box vboxnet0 which was 192.168.56.1 in my case worked.
    – xji
    Nov 17, 2014 at 5:11
  • 2
    Damn, I didn't realise it changed from 10.0.2.2 to 10.0.3.2 after an update. Thanks for that!
    – twig
    Jun 24, 2015 at 23:44
  • I changed only one digit in url ".setRootUrl("10.0.3.2:8080/_ah/api/")" and it worked for me! Great! Jul 2, 2015 at 10:36
  • 1
    10.0.3.2 worked for me on OSx and Genymotion 2.8.1. A bit surprised I didn't even have to add anything to my Apache vhost configuration or hosts file, it just works! :D
    – Magnus
    Apr 3, 2017 at 15:51
26

you need this structure

Genymotion

http://10.0.3.2/

Default AVD

http://10.0.2.2/

the http it's very important and the port it's for default It depends on your server.

you can check this url in your browser the smartphone

enter image description here

20

The IP returned by ipconfig dit not work for me. However 10.0.3.2 worked for me even though the IP address in the Wifi setting is 10.0.3.15.

Genymotion 2.2.0

2
  • 1
    Thank you sir. With this IP I can connect to the computer hosting the Genymotion emulator regardless of the network I'm in. That's what I came looking for :D
    – josebama
    Jun 4, 2014 at 10:55
  • loopback 10.0.3.2:3000
    – Sonu Kumar
    Apr 6, 2016 at 6:27
12

it works for me by using http://192.168.56.1:8080

to know your IP just use the following command

  • for (mac and linux) ifconfig vboxnet0
  • windows command ipconfig vboxnet0

and make sure the port is collect.

I got the answer from : here

2
  • what is vboxnet0? Where will I get this string "vboxnet0"?
    – sham
    Jan 22, 2017 at 14:39
  • @sham ipconfig for mac maybe linux, ifconfig for windows May 12, 2018 at 23:39
6

Genymotion! It works for me using IP 10.0.3.2 but depends on your localhost port. Apache it will be just IP and Tomcat with default port 8080. Here I take screenshots.

1. Apache Screenshot

Genymotion Apache

2. Tomcat Screenshot

enter image description here

Hope this is helpful. Thanks!

2
  • Am trying to follow all your steps but it doesn't seem to work... Any settings in VB??????????????? May 20, 2016 at 19:17
  • @KarueBensonKarue, first make sure that your URLs executed in browser. May 20, 2016 at 19:52
5

Intro:

Long story short, Genymotion is running on Virtualbox, and the default network configuration is “Host-Only.” This method essentially emulates a physical network that is shared by your Genymotion VM (the emulator) and your host machine. The name of the network is vboxnet0, and if you run “ifconfig vboxnet0” (or “ipconfig vboxnet0” if running Windows) on your host machine, you should receive the IP address of your host on the vboxnet0 network. The default IP is most likely 192.168.56.1.

Solution:

This is the IP address to use when accessing your host machine from the Genymotion emulator. For my Rails app, this meant calling “192.168.56.1:3000” instead of “10.0.2.2:3000.”

Link:

http://bbowden.tumblr.com/post/58650831283/accessing-a-localhost-server-from-the-genymotion

1
  • In my experience, there was no need to use a port, just use the IP address.
    – ThomasW
    Mar 26, 2014 at 6:08
3
  1. run xampp(def 127.0.0.1:80) and go to Control Panel\All Control Panel Items\Network and Sharing Center
  2. select connection

enter image description here

2

When i used genymotion in my ubuntu

i used the ip address of the virtual machine as local host and it worked .

in virtual box goto file > preferences > network > select host only network and select adapter tab copy the ipv4 address and use it instead of localhost ...

like http://192.168.56.1/qrstuff/json/

1

Check your Internet Connection on PC first, then Turn on Wifi in your Genymotion Emulator Device

After goto Cmd by Pressing ctrl+r then type Cmd and hit enter you will see an command line window

type ipconfig and hit enter...

here you can see your ipv4 address type it in your Genymotion Emulator Device's Browser now you can connect to your local webserver....

0

In my case 10.0.3.2 didn't work. I changed to virtual box host-only network : 192.168.128.2 it works. You have to try other virtualbox adapters IP if it doesn't work with 192.168.56.1. My environment is behind a corporate proxy and I was running an embedded undertow server. Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.