代码之家  ›  专栏  ›  技术社区  ›  Andrew

Android emulator忽略system/etc/hosts文件中的设置

  •  1
  • Andrew  · 技术社区  · 6 年前

    主机 文件所以我在电脑上编辑了配置 系统/etc/主机 . 之后,我可以在PC浏览器上使用我的主机。

    PC主机文件img: enter image description here _

    然后我尝试在Android Studio Emulator(同一台PC)上打开同一个主机。浏览器显示错误“网页不可用…ERR\u NAME\u not\u RESOLVED”。奇怪的是,我假设emulator会使用PC OS主机属性(比如在Mac上使用X-Code emulator)。

    浏览器img中的模拟器错误: enter image description here _

    Emulator托管文件img: enter image description here _

    如何使emulator与我的主机ip主机名对一起工作?也许我错过了什么?

    3 回复  |  直到 6 年前
        1
  •  1
  •   wezten    6 年前

    设备中的最后一行 hosts

        2
  •  0
  •   user5956451 user5956451    6 年前

    根据Emulator文档,这是预期行为:

    注意,这通常意味着emulator忽略“hosts”文件的内容(Linux/OS X上的/etc/hosts,%WINDOWS%/system32/hosts)。

    但是,您可以使用10.0.2.2从emulator内部访问主机(而不是在您的示例中进行测试)

        3
  •  0
  •   Andrew    6 年前

    系统管理员以某种方式解决了这个问题。所以现在我用 -dns-server option 手动指定DNS服务器的地址。我的测试api要求工作。

    emulator -avd nexuss5 -dns-server xxx.xx.x.x