Editing the hosts file on android virtual devices

I hosts several web sites on an Ubuntu server that I run at home, and I do this using Apache 2 name based virtual hosts. This allows me to host multiple web sites on the same server at the same IP address. This causes problems when trying to test how the websites look on mobile devices on the local network.

To enable multiple sites to be hosted at the same ip address Apache2 will redirect the http request to correct web site files based on the domain name supplied with the http request. For example both site1.com and site2.com can resolve to the same ip address, but Apache will route requests to site1.com to the virtual name host files for site1 and requests to site2 to the virtual name host files for site 2. You can read more about this here.

The problem with this set up is that I can't browse to the non-default virtual hosts using the IP address of my local server, and my ISP don't let requests from my IP address route back to my IP address, i.e. I can't browse to site2.com via external DNS look ups.

The obvious way around this is to add entries to my local hosts files;                            site1.com                            site2.com

Great! I can now browse to non-default virtual hosts from my local machine. However, I have been doing some responsive web design using a mobile first approach, and I need to test my sites from a browser on my android phone. To do this I have used the Android development tools to create an Android Virtual Device and am using the browser on that device, running in the android emulator to test the site. However, the android emulator device doesn't use the hosts file on the machine on which you're running, it instead uses it's own hosts file. In order to browse to my site2.com I need to modify the hosts file on the avd. To do this you can;

Start the emulator;
<android-sdk-dir>/tools/emulator -avd <avd-name> 

Remount the android debug bridge as writable;
<android-sdk-dir>/platform-tools/adb remount

Pull the host file off the device;
<android-sdk-dir>/platform-tools/adb pull /system/etc/hosts ~/

I can then add the ip->site mappings to the hosts file in ~/hosts and push it back to the avd;
<android-sdk-dir>/platform-tools/adb push ~/hosts /system/etc/hosts

If you find you get a message stating that there is no space left on the device, you may need to modify the avd definition to have a greater partition size.

You can use a similar technique to modify the hosts file on a real android device.



  1. I mean, what you say is valuable and everything. However imagine if you added some
    great photos or video clips to give your posts more, “pop”!for more visit

  2. The inability of versions to run compatibility backwards or forwards mean that apps available on either version will only run on versions that are exactly the same as theirs.gerald winata gozali

  3. Rather than managing with an instant software program or application, with modified software you can make sure that what you will get will be totally fit for reason.Open Source crowdfunding software for sale

  4. The accompanying agenda can be utilized to investigate the authenticity and exactness of upkeep prerequisites.
    itools crack reddit

  5. One of the fundamental chances given by the software area is moderately low section hindrance. Since the software business isn't capital escalated, Brampton Bookkeeping Brampton


Post a Comment

Popular posts from this blog

Android logging put to bed.

Using an Ubuntu VM to connect to a VPN using juniper network connect.

The Simple Way to Create an AM Authentication Node Project