Accessing your machine through machine name with Android Emulator on Windows

Accessing your machine through machine name with Android Emulator on Windows

I’ve been working on a mobile project recently, using Xamarin, Android/iOS emulators and Visual Studio 2017.

In my local environment (Windows 10), my emulators need to be able to communicate with my machine to access services, using machine name. By default, this is not possible. You will notice that hitting a url, with your machine name in it, from your emulator, does not properly resolve, and this is due to the default hosts file on an Android emulator, and the way it treats routing to 127.0.0.1.

Here are the steps I was able to take, on Windows 10, in order to hit my machine via machine name, from my android emulator, on my local network.

1) Open two separate administrator command prompts.

2) In the first prompt, CD to C:\Program Files (x86)\Android\android-sdk\tools (this path may be slightly different on your machine, but should be close enough to figure out the correct path)

3) Then run: C:\Program Files (x86)\Android\android-sdk\tools>emulator -avd YourEmulatorNameHere -writable-system -partition-size 128 (filling in your emulator name in place of YourEmulatorNameHere)

This opens your emulator, and puts it into a writable mode, which is needed to push a modified hosts file to it.

4) Now from your 2nd command prompt:

5) CD to C:\Program Files (x86)\Android\android-sdk\platform-tools (this path may be slightly different on your machine, but should be close enough to figure out the correct path)

6) Run: adb remount

7) Run: adb pull /system/etc/hosts c:\temp

This will pull a copy of the emulator’s host file to c:\temp\hosts

8) Open the pulled hosts file and modify it to be:

127.0.0.1 localhost
10.0.2.2 yourMachineNameHere

9) Run: adb push c:\temp\hosts /system/etc

Now, with any luck, on your emulator you should be able to hit your machine via a machine name url.

I hope this helps someone else having these issues. Good luck!

Share Your Thoughts!

Testimonials

What My Clients Say

Karin - Hope and Future

Brent has always been very prompt and generally exceeds our expectations with his work. His maintenance fee is very reasonable. I strongly recommend him!  We get many compliments on our beautiful web site!

Dan

I contacted Krueger Web Design and Brent did everything.  He setup a test site with the changes so we could verify everything was correct before we transferred from my old hosting provider.  During the setup and conversion Brent was extremely professional and responsive. He responded to any issues the same day.

Dan Kaufman
Emily - GFCLT

We've had a great experience working with Krueger Web Design. Prompt responses, great ideas, effective work... all at a reasonable price! This was the perfect fit for our organization.

Mahmud - ACMC

I would love to recommend you to anyone! You have been very helpful when we needed you the most.

Brian - SEMNIC

Working with Krueger Web Design was effortless. Communicating what I wanted for the website and the results that I saw were identical. The customer service was always prompt and I am completely satisfied with the product.

Zach - Stadium Club

Exactly what I wanted! Fast turnaround time and very affordable. Answered all of our questions quickly and made adjustments promptly. Very easy to work with and puts everything into terminology that even I can understand!

Contact Krueger Web Design

Have a question for me? Need an estimate on some work? You can email me at brent@kruegerwebdesign.com or drop me a line using the button below:

Copyright © 2017 Krueger Web Design - All rights reserved
Web Design in Madison, WI