doushizhou4477 2015-11-19 18:50
浏览 115
已采纳

Golang:使用UDP连接时,带有gomobile的Android应用程序崩溃

I wrote Android apps in go with mobile package, the apps crash after reaching the following code:

ServerAddr,_ := net.ResolveUDPAddr("udp",SERVER_IP_AND_PORT)
LocalAddr, _ := net.ResolveUDPAddr("udp", ":0")
Conn, err := net.DialUDP("udp", LocalAddr, ServerAddr)
buf := []byte("lalala")
_,err := Conn.Write(buf) //apps crash on this line

Where (actual ip is represented by "x"):

const SERVER_IP_AND_PORT string = "xxx.xx.xx.xxx:10001" 

I tested the code on my laptop and they work perfectly fine. I use mobile package only for creating apk files to do the UDP tests.

I tried to use "log" package to trace errors but it doesn't work. I downloaded many logcat apps but none can catch the error logs (or even log.Print("AAA")). I also tried to write logs in files but don't work either, please check out this question.

Anyway, does anyone have any idea about what the problem is, or any ways to locate the bug? (And please avoid using Android Studio which I have a thousand more problems to even install it correctly)

Thank you very much!

  • 写回答

1条回答 默认 最新

  • duanjianxi8439 2015-11-20 12:12
    关注

    By now we have to manually add permissions to AndroidManifest.xml, gomobile package is not doing that (feature request is filed). Before they implement this feature we have to do it manually.

    For more information please refer to this question:

    Golang: Gomobile app cannot generate files

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部