How to edit / etc / hosts file in Android Studio emulator running nougat?

Does anyone know how to edit the / etc / hosts file inside an Android studio emulator running in nougat? I will edit it so that I can use my virtual host on my local web server. I tried editing it through the terminal using adb, but it returns a read-only file system. I also tried using chmod, but it still fails.

Update: I also tried pulling and clicking files using adb $. / Adb -s emulator-5554 push ~ / Desktop / hosts / system / etc / hosts

adb: error: could not copy '/ Users / Christian / Desktop / hosts' to '/ system / etc / hosts': could not create file: read-only file system

+17
source share
8 answers

I managed to edit the / etc / hosts file by running the emulator using -writable-system and remounting the emulator using adb remount. After that, the hosts file inside the emulator is available for editing. I tried to push / replace the file and succeed.

+4
source
1) android-sdk-macosx/tools/emulator -avd <avdname> -writable-system 2) ./adb root 3) ./adb remount 4) ./adb push <local>/hosts /etc/hosts 

Android file host may be

 /etc/hosts <--- This worked for me /etc/system/hosts /system/etc/hosts 

Check

 1) ./adb shell 2) cat /etc/hosts 3) ping customsite.com 
+42
source

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.

+10
source

Follow these steps:

  • Run the emulator in write mode: ./emulator -avd <emulator_name> -writable-system
  • remount: adb remount
  • click the hosts file in the application : adb push hosts /system/etc/

Note:

  • Run one and only one emulator name with the steps above.
  • The executable emulator is inside android-sdk. For me it was under sdk/emulator .
  • The attached hosts file will resolve www.facebook.com to 127.0.0.1, so it blocks www.facebook.com on the emulator.
+2
source

You can use the ADB shell to edit the file by changing access (read-only to RW)

+1
source

Step by step

  1. Do not create AVDs with Google Play images .
  2. Use, for example, the Google API Intel System x86 System Image .
  3. Run the emulator with the following command ...

     emulator.exeavd <avd name> -writable-system 

For instance:

  C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\emulator>emulator.exe -avd Pixel_API_25 -writable-system emulator: WARNING: System image is writable HAX is working and emulator runs in fast virt mode. audio: Failed to create voice 'goldfish_audio_in' qemu-system-i386.exe: warning: opening audio input failed audio: Failed to create voice 'adc' 
  1. Root and remount AVD as following ...

     C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb root C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb remount remount succeeded C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb shell eneric_x86:/ # cd system generic_x86:/system # cd etc generic_x86:/system/etc # cat hosts 127.0.0.1 localhost ::1 ip6-localhost generic_x86:/system/etc # echo "192.168.1.120 ilyasmamun.blogspot.com" >> hosts generic_x86:/system/etc # cat hosts 127.0.0.1 localhost ::1 ip6-localhost 192.168.1.120 ilyasmamun.blogspot.com generic_x86:/system/etc # 
+1
source

Try to answer @POW,

Make sure you have an empty line after the last record of the hosts file. If you use tabs in the hosts file, replace them with spaces "Restart Android" and try again:

 adb reboot 
0
source

I tried the explanation @ylias

recordable system

But when I tried ADB root

adb root

I give an error and cannot remount the device. Could you help me

reboot adb

0
source

Source: https://habr.com/ru/post/1261180/


All Articles