How to Modify Android Emulator Hosts file

Posted: February 22, 2011 in Android
Tags: , , ,

Update: Instead of modifying hosts file, a better way is to set the DNS to your own DNS server. Setting up a DNS server for local development should be easy.

Modifying hosts file is very important and useful trick for web development. Android hosts file is located in /system/etc/ directory.

Below is the steps to modify Android emulator hosts file.

  • emulator -avd <you_avd_name> -partition-size 128. Start emulator from command line. I have tried to start emulator via Android SDK Manager, but kept geting Out of Memory when pushing back the file.
  • adb remount. Remount the file system, otherwise when pushing back the file, you will get error: read-only file system.
  • adb pull /system/etc/hosts /your/local/path. Pull the hosts file from emulator.
  • adb push /your/local/path/hosts /system/etc. Push back the hosts file with your changes.

For locked android phone, we need unlock it to gain the root privileges first.

If you will receive the error that “more than one device and emulator”, you need specify which emulator or device you want to connect to.

Type the command adb devices to check the device names and add -s <device_name> to the above adb commands.

  1. lc says:

    the modify will be invalid when reboot the emulator, can this be resolved?

    • Xiaojie says:

      Emulator will auto reload ramdisk.img when reboot. You need modify the hostfile in side. ramdisk.img is located in your SDK directory, under platforms/android-x/images. I have never tried before, don’t have the details.

  2. kamal says:

    i have a mac and this commande “emulator -avd you_avd_name -partition-size 128”
    dont work and i get this error:
    -bash: emulator: command not found

  3. […] Posted: February 22, 2011 in Android Tags: ADB, Android, Emulator, Hosts 4 […]

  4. […] If you also want to access your other development machine from the emulator, you may either modify the emulator host file, or set the emulator DNS to your own one. You can refer to my previous post How to Modify Android Emulator Hosts file […]

  5. […] Недолгий поиск приводит к нескольким аналогичным решениям, в которых описано, как можно отредактировать hosts файл […]

  6. […] PS: if you don’t know how to modify the emulator hosts file, you can refer to my other post here […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s