How to edit hosts file on android emulator API 30 (Android R)

1.1k Views Asked by At

I'm trying to edit the hosts file on an android emulator with API 30 - Android R. I have completed remount successfully but it says

Remount succeeded. Reboot device for changes to be effective

I am stuck on this step because no matter what way I reboot the emulator, it goes to

Device offline

and shows just a black screen. It gets restored only if I do a factory reset, but again the emulator file system becomes read-only and I cannot edit the hosts file.

The solutions I tried are as follows:

First step is common. In adb command prompt:

cd [...\Android\android-sdk\emulator directory]
emulator -avd [EMULATORNAME] -writable-system

Then in system command prompt,

cd [...\Android\android-sdk\platform-tools directory]

Method 1:

adb root
adb remount

Here remount succeeds but I need to reboot the device. All these ways of rebooting result in Device Offline state and black screen:

  1. adb reboot
  2. Manually restarting emulator by long pressing power button
  3. In adb command prompt, pressing Ctrl + C to stop the emulator and starting again with: emulator -avd [EMULATORNAME] -writable-system

If I ignore the reboot and try to edit the hosts file pushing a new like this:

adb push hosts /system/etc

Then I get

Error, cannot write to a read-only file system.

Method 2:

adb shell
su
mount -o remount,rw /sys

This gives no error or success message. Then if I try any write operation such as:

adb push hosts /system/etc

or

cat hosts

10.1.3.5 bla.blabla.com >> hosts

Then it still says

Error, cannot write to a read-only file system.

I have already tried these links and solutions with no success:

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

I can't edit android emulator's host file

Android emulator-5554 offline

android emulator sdk 10 api 29 won't start after remount and reboot

Please help. Thanks in advance!

0

There are 0 best solutions below