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!