This is how I was able to do this while working on OSX. After reading a bunch of different instructions, nothing worked for me until someone mentioned that you have a very narrow window for copying a file from your disk to an emulated device or it becomes read-only again.
- Launch your emulator.
- In your terminal, find the "platform-tools" folder for your devices.
- Prepare the hosts file that you want to copy to your device (in my case, I placed it on the desktop)
- Group a bunch of commands to quickly copy the file. This is what worked for me
./adb root && ./adb -s emulator-5554 remount && ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts 'emulator-5554' is the name of my device, which you can find by typing ./adb devices
after that the terminal answered
restarting adbd as root remount succeeded [100%] /system/etc/hosts
you can very well that the copy was successful ./adb shell and then cat /system/etc/hosts
Then I was able to connect to my virtual hosts from an emulated device
Just to be complete, here is how my hosts file looked like 10.0.2.2 my-virtual-host
I hope this helps someone as I have been trying to figure this out for quite some time.
source share