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,then I push hosts file,I get some errors:
step4
adb push hosts /system/etc/hosts
error information:
adb: error: failed to copy 'hosts' to '/system/etc/hosts': couldn't create file: Read-only file system
envirements information:
osx ei capitan
android emulator: android 7.1.1
android studio: 2.2.2
Contact the administrator to obtain permission” error. Hit the start menu or press the Windows key and start typing Notepad. Right-click Notepad and choose Run as administrator. Now you'll be able to edit and save changes to your HOSTS file.
Install ES File Explorer. If you don't already have this app installed on your Android, you can get it free from the Play Store. You must have a rooted Android to edit the hosts file.
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:
adb devices
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 :)
After pushing the hosts file run adb reboot
and you will have no problem with the black screens anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With