简体   繁体   English

Android 模拟器的主机文件

[英]Hosts file for Android emulator

I'm trying to setup hosts file for android emulator.我正在尝试为 android 模拟器设置主机文件。 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".但是当我执行 adb remount 时,它会写“重新挂载 / 超级块失败:权限被拒绝”。 I'm going to adb shell, but it also writes an error.我要去adb shell,但它也写了一个错误。

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.我重新安装了 Android Studio 两次,但没有帮助。 Could anyone help pls?有人可以帮忙吗?

Usage of -writable-system flag made adb remount work.使用 -writable-system 标志使 adb remount 工作。 Hosts were replaced with the new file.主机已替换为新文件。

Launched emulator as: emulator.exe -writable-system -avd Nexus_5X_API_28_x86启动模拟器: emulator.exe -writable-system -avd Nexus_5X_API_28_x86

The hosts file is located at a directory that is not allowed to write over a file. hosts 文件位于不允许覆盖文件的目录中。 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.在这一步之后,应该log remount成功了。 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:

adb reboot

Emulator will restart itself.模拟器将自行重启。 After this, you can remount the adb:在此之后,您可以重新挂载 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM