Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't edit android emulator's host file

Tags:

android

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  
like image 931
haibinpark Avatar asked Dec 14 '16 09:12

haibinpark


People also ask

Why cant I edit the hosts file?

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.

Can you edit hosts file on Android?

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.


2 Answers

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 :)

like image 130
JoeRoot Avatar answered Sep 18 '22 05:09

JoeRoot


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

like image 36
Captain Avatar answered Sep 17 '22 05:09

Captain