Skip to content Skip to sidebar Skip to footer

I Can't Edit Android Emulator's Host File

I try to edit android emulator's host file.I follow steps: step1 adb root step2 adb remount step3 adb pull /system/etc/hosts . then I add new line for customer host information,th

Solution 1:

I just ran into the same problem and made it work.

Run the emulator:

emulator -avd <EMULATORNAME> -partition-size 512 -writable-system

I believe that -writable-system param is the thing that fixed it for me.

In another terminal/cmd prompt:

adb root

adb -s emulator-5554 remount

adb -s emulator-5554 pull /system/etc/hosts hosts

Now, work your magic (add the IP to host file)

adb -s emulator-5554 push hosts /system/etc/hosts

Additional info:

  • emulator-5554 is the device name, you can find yours with adb devices
  • emulator program is located inside android-sdk/tools
  • adb program is located in android-sdk/platform-tools

Important update from comments:

Please check the comment from steven to this post about running adb reboot before running adb root. This might be important to being able to start the emulator from AVD manager.

Captain suggests to run adb reboot after pushing the host file to avoid blackscreen error.

Happy debugging :)

Solution 2:

After pushing the hosts file run adb reboot and you will have no problem with the black screens anymore.

Solution 3:

I had problems with the other solutions, so i tested a lot and now i decided to write another answer and i hope it is useful for others.

Here are my steps to success (Android Studio on win 10):

  • Start Android Studio and open the AVD Manager and start your Emulator.
  • Open a powershell and navigate to your android sdk/platform-tools/
  • .\adb.exe reboot -writable-system (your emulator should reboot now)
  • .\adb.exe root
  • .\adb.exe remount
  • .\adb.exe pull /system/etc/hosts C:\Temp\hosts
  • Èdit your hosts file
  • .\adb.exe push C:\Temp\hosts /system/etc/hosts
  • .\adb.exe unroot
  • Now you can open a browser in your emulator and open your custom domain to check if your hosts file has been changed.
  • Click the close-icon of your emulator to force a shutdown with snapshot saving. You should see a "Saving state..." message.
  • Now start your emulator again from AVD Manager. Your hosts file should persist. So check your domain again.

I had very strange issues with unstartable emulators after booting in writable-system mode, rooting and stopping emulator without doing the unroot. The problem is: whenever the snapshot fails the emulator will do a cold boot and your hosts file is gone. You need to repeat all the steps in that case.

Post a Comment for "I Can't Edit Android Emulator's Host File"