Ida
Ida

Reputation: 41

Hosts file for Android emulator

I'm trying to setup hosts file for android emulator. I saw this advice:

 adb remount 
 adb push hosts /etc/system/hosts (most tutorials suggest
 this file) 
 adb push hosts /system/etc/hosts (some VM systems seem to
 prefer this file instead!, for me this worked)

But when I do adb remount it writes "remount of the / superblock failed: Permission denied". I'm going to adb shell, but it also writes an error.

generic_x86:/ # mount -o remount,rw /system
mount: '/system' not in /proc/mounts
1|generic_x86:/ # mount -o rw,remount,rw /system
mount: '/system' not in /proc/mounts
generic_x86:/ # mount -o remount,ro /system
mount: '/system' not in /proc/mounts
1|generic_x86:/ # whoami
root

I reinstalled Android Studio twice it didn't help. Could anyone help pls?

Upvotes: 2

Views: 7131

Answers (3)

MisterAnt
MisterAnt

Reputation: 536

This is my final solution:

  • Launch Device Manager.

  • Create LEGACY device Android ISO.

  • What do you want like: adb root adb remount adb reboot

  • ISO in emulator is ready to use!

Only Legacy Android ISO can operate with root. I tried now and it works perfectly!

Upvotes: 0

Ida
Ida

Reputation: 41

Usage of -writable-system flag made ADB remount work. Hosts were replaced with the new file.

Launched emulator as: emulator.exe -writable-system -avd Nexus_5X_API_28_x86

Upvotes: 2

Faruk Yazici
Faruk Yazici

Reputation: 2404

The hosts file is located at a directory that is not allowed to write over a file. So, you should first copy hosts to somewhere else, edit it, and then copy it back.

For example, let's work on the standard emulator:

Run the following command while the emulator is open:

adb devices

This command will show the running emulators. Run the following command to disable the emulator's read-only behaviour:

adb -s emulator-5554 remount

After this step, it should log remount succeeded. Then you should copy the emulator to another directory for editing:

adb -s emulator-5554 pull /system/etc/hosts ~/Desktop/

After this step, it will log about the file transfer's success. Now you can edit the hosts file. After the edit, you should push the file back. First of all, you should reboot the adb:

adb reboot

Emulator will restart itself. After this, you can remount the adb:

adb -s emulator-5554 remount

After the remount, you can push back hosts file:

adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts

Upvotes: 0

Related Questions