adventures in technology
Hosts files and the Google Android emulator
Using the Google Android emulator is a good way to test how a website behaves on Android devices.
Connecting to your local computer
http://10.0.2.2 is the URL to connect to a website hosted on your local computer. localhost or 127.0.0.1 will not work! This is all defined in the documentation on Android emulator networking.
Using a hosts file
The Android emulator will not make use of your local hosts file. This is unfortunate when your website relies on host headers to work correctly (eg. SharePoint). What you need to do is edit the hosts file on the Android emulator image itself.
- start your Android Virtual Device (AVD):
emulator -avd myAvdNameHere -partition-size 128
Located in C:\Program Files (x86)\Android\android-sdk-windows\tools\ on Windows 64bit
Note
The partition-size parameter is needed to expand the image size to prevent an error in step 5. If you try and perform these steps after starting the emulator from the UI you will receive the following error:
failed to copy ‘c:\temp\hosts’ to ‘/system/etc/hosts’: Out of memory - remount the device image as writable:
adb remount
Located in C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\ on Windows 64bit
- save a copy of the existing hosts file to a temporary location on your host computer:
adb pull /system/etc/hosts c:\temp
- edit the hosts file adding an entry pointing to your host computer:
127.0.0.1 localhost 10.0.2.2 mytesthost
- save the edited hosts file to your Android emulator:
adb push c:\temp\hosts /system/etc
You can now browse to your entered hostname in the Android browser.

| Print article | This entry was posted by brad on February 13, 2011 at 4:49 pm, and is filed under Software. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
-
Msamsulbahri
-
http://www.bradcurtis.com Brad Curtis
-
Msamsulbahri
-
malbers
-
http://pv4.com.br/index.php?font-size=larger Pv4
-
Notelodigo
-
http://pulse.yahoo.com/_JRZBAXKM33SANDGRRBQHDBEHIQ Gerard Araujo
-
Shreyasshanka
-
lu
-
http://congdongit.org/subscription.php?do=addsubscription&t=1699 dien dan cong dong it lon nhat viet nam
-
http://www.morestuffabout.net/2012/01/faking-dns-entries-for-the-android-emulator-using-unbound/ Faking DNS entries for the Android emulator using Unbound | More stuff about .NET
-
WilliamB
-
Jozs