Oh! so you want to update a hosts file just like I wanted and spoiled many minutes playing with what works. Let’s go through this process to make it work for you as well (hopefully!)
Google Android emulator is an amazing tool to test out your apps, Hybrid or Native.
There are many cases when we want to use hosts file to point a domain to a machine located in local network.
A good place to start reading about what is or is not possible with emulator when it comes down to networking is to read this help page on Android emulator networking.
Edit the hosts file in Android emulator
- Start your Android Virtual Device (AVD):
12emulator -avd AVD_NAME_HERE -partition-size 256
Emulator is located under “C:\Program Files (x86)\Android\android-sdk\tools” folder, we are adding the partition size so we give enough buffer to write to our hosts file without any error. The error you may get is
failed to copy ‘c:\temp\hosts’ to ‘/system/etc/hosts’: Out of memory
- Second step is to remount the device image by using the command below
adb stands for Android Debug Bridge, to read more on this command please go visit this page, this program can be found in “C:\Program Files (x86)\Android\android-sdk\platform-tools” location of your windows install.
- Next step is to get the default hosts file and save it on your local hard drive using the command below, I am using the destination location as c:\copied, yours can be anything
12adb pull /system/etc/hosts c:\copied
- Make the new entries to you hosts file. Important: Now in the example below I am using a white space instead of a TAB delimiter between IP address and hostname. For me, TAB didn’t work. But you can try both to see what works for you. Also not that I am appending my entry to the existing file rather than editing it with notepad.
12echo 192.168.1.74 jas-pc.jaspreetchahal.org >> c:\copied\hosts
- Let’s save the edited file and send it back to the emulator.
12adb push c:\copied\hosts /system/etc
Now you are able to browse your domain from local network.
I hope this helps