73

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

mownier
  • 1,719
  • 2
  • 13
  • 27
  • 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. – Chris Stratton Nov 28 '13 at 03:39
  • Ahm thanks for the comment. What i am aiming is that, i want to access the 'http://localhost:8888' in my computer, which is running MAMP, from a Genymotion android emulator. Is that possible? – mownier Nov 28 '13 at 03:57

10 Answers10

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.

Community
  • 1
  • 1
Coderji
  • 7,655
  • 5
  • 37
  • 51
  • 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 '14 at 05: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 '15 at 23:44
  • I changed only one digit in url ".setRootUrl("http://10.0.3.2:8080/_ah/api/")" and it worked for me! Great! – Alex Zezekalo Jul 02 '15 at 10:36
  • Worked Perfectly Thanks a lot. – Saraschandraa Dec 01 '16 at 15:04
  • 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 03 '17 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

Community
  • 1
  • 1
David Hackro
  • 3,652
  • 6
  • 41
  • 61
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

Sydney
  • 11,964
  • 19
  • 90
  • 142
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

ikuchris
  • 1,162
  • 1
  • 15
  • 33
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!

Madan Sapkota
  • 25,047
  • 11
  • 113
  • 117
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

Brains
  • 594
  • 1
  • 6
  • 18
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

sirmagid
  • 1,090
  • 1
  • 16
  • 23
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/

Ameen Maheen
  • 2,719
  • 1
  • 28
  • 28
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....

Karthick
  • 281
  • 2
  • 7
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.

IldiX
  • 591
  • 1
  • 7
  • 16