doushizhou4477 2015-11-20 02: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 20: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

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

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据