在android中缺少/etc/resolv.conf

She*_*lva 5 android go

我将我的Go源代码交叉编译为Arm以在Android中运行.该程序在Android设备的终端中运行,但是我收到一条错误消息,指出缺少/etc/resolv.conf.我的程序在进行http调用时严重依赖net/http库.

如何在Android中处理此错误?

One*_*One 5

截至目前,您无法使用内置的 net/http 连接到主机名,请检查此问题。

您可以使用的解决方法很少。

  1. 如果您有 root 访问权限,则在程序启动时生成 /etc/resolv.conf,虽然丑陋但简单。

  2. 将 resolv.conf 存储在某处并修补http://golang.org/src/pkg/net/dnsclient_unix.go#L169以使用该自定义路径。

  3. 通过执行和$GOROOT/src/pkg/net/dnsconfig_unix.go来获取名称服务器的补丁。getprop net.dns1getprop net.dns2

  4. 在https://gist.github.com/ernesto-jimenez/8042366上实现完整补丁