Connect VS Android emulator to localhost

1.7k Views Asked by At

I'm developing a Xamarin.Forms 4 application with Visual Studio 2015 update 3 on Windows 10. Now I've setup an ASP.net web API and I'm trying to connect to it when it's been run on localhost with VS Andorid emulator 1.1 for Kitkat 4.4 (Andorid 4.4 API 19). Although my app works with the Windows Phone emulator, it doesn't with the Android emulator.

I've tried to connect to the 10.0.2.2 or 169.254.80.80 like it was suggested here but it doesn't work neither from the emulator nor the device itself. I've also enabled IIS express to accept request from external devices with the second solution provided here so I'm out of ideas.

Please elaborate on your answers as it seems that a lot of people are running into the same issue.

Thanks a lot in advance!

2

There are 2 best solutions below

1
On

I had been on a mission for days trying to solve this. Screwing with ports and the iis bindings. But I found this

https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

This package creates a psuedo URL that exposes the localhost:[port] to the emulator.

Troubles be gone.

0
On

Don't forget to run Visual Studio as Administrator. I had similar problem until I ran it as Administrator.

Also, I like more how the solution is described here: http://briannoyesblog.azurewebsites.net/2016/03/06/calling-localhost-web-apis-from-visual-studio-android-emulator/