从Android Studio中的模拟器访问Localhost和Virtualhost?

Kum*_*arS 5 android android-emulator genymotion

我想从android studio模拟器或genymotion访问localhost,而无需键入IP地址,而是键入localhost或域名。如果您正在从事Web开发,那么您可以像C:\Windows\System32\drivers\etc\hosts在Windows系统中的文件中为IP分配域一样。我尝试了一些博客的步骤,但无法弄清楚。

请帮帮我。谢谢!

Sha*_*ath 4

您可以尝试从 android studio 的终端编辑主机文件。

首先进入终端并启动模拟器 emulator -avd AVDNAME -partition-size 128

其次重新挂载 AVD 使其可写 adb remount

第三步将主机文件从模拟器拉到本地计算机 adb pull /etc/hosts

第四,根据需要使用本地编辑器编辑host文件 198.0.0.1 localhost

最后将编辑好的文件从本地推送回模拟器adb push hosts /etc/hosts

现在,输入 localhost 或您在主机文件中分配的域。

希望这已经足够了!