dora0817
dora0817
2014-09-11 10:52
浏览 222

在Android中缺少/etc/resolv.conf

I cross compiled my Go source code to Arm to run in Android .The program runs in the terminal in the Android device, but I get an error saying that /etc/resolv.conf is missing. My program heavily relies on the net/http library in making http calls.

How can I handle this error in Android?

图片转代码服务由CSDN问答提供 功能建议

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

如何在Android中处理此错误?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duandou8120
    duandou8120 2014-09-11 14:21
    已采纳

    As of right now you can't use the built in net/http to connect to hostnames, check this issue.

    There are few workarounds you could use.

    1. generate /etc/resolv.conf on your program start if you have root access, ugly but easy and simple.

    2. store resolv.conf somewhere and patch http://golang.org/src/pkg/net/dnsclient_unix.go#L169 to use that custom path.

    3. patch $GOROOT/src/pkg/net/dnsconfig_unix.go to get the nameservers by executing getprop net.dns1 and getprop net.dns2.

    4. implement the full patch at https://gist.github.com/ernesto-jimenez/8042366

    点赞 评论

相关推荐