I am unable to make a http request from a Go fyne application running on android, below is a simple example to show the issue
package main
import (
"io/ioutil"
"net/http"
"log"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
)
func main() {
app := app.New()
w := app.NewWindow("Android http issue")
w.SetContent(widget.NewVBox(
widget.NewLabel("Run test"),
widget.NewButton("Connect", func() {
go func() {
HttpGetData(w)
}()
}),
))
w.ShowAndRun()
}
func HttpGetData( win fyne.Window) {
resp, err := http.Get("http://date.jsontest.com/" )
if err != nil {
log.Println("%v", err)
}
defer resp.Body.Close()
bodyBytes, _ := ioutil.ReadAll(resp.Body)
StartScreen(win, string(bodyBytes))
}
func StartScreen(win fyne.Window, data string) {
l := widget.NewLabel("data" +data)
win.SetContent(l)
}
I can run the code on linux with go run -tags mobile . -t
first screen
then I can fire the event to make a http get request to the remote server and see the http response in the gui
as we can see everything works via go run -tags mobile . -t
on linux
now I package as an apk using fyne
fyne package -os android -appID basic.client -icon ico.png
install with adb adb install <path to apk>/basicExample.apk
When I run the app in android I get to the first screen, then fire the event as before.
The http request is never fired, I only get a crytpic error in logcat
F/libc ( 4711): Fatal signal 6 (SIGABRT), code -6 in tid 4739 (basic.client)
E/InputDispatcher( 535): channel '344d7ddf basic.client/org.golang.app.GoNativeActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
any help would be greatly appreciated
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="basic.client"
android:versionCode="1"
android:versionName="1.0">
<application android:label="Client" android:debuggable="true">
<uses-permission android:name="android.permission.INTERNET" />
<activity android:name="org.golang.app.GoNativeActivity"
android:label="Client"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="client" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
UPDATE from comment
android version 28
golang version go1.14.4 linux/amd64
fyne version fyne.io/fyne v1.3.0
Update 2
Added following attributes to the application tag in the manifest
android:usesCleartextTraffic="true" tools:targetApi="28"
Results in following error for the fyne package
command
failed to find table ref by "attr/usesCleartextTraffic"
I added a print statement to the fyne package
command to log the build environment variables, this is what they look like
GOOS=android
GOARCH=arm
CC={path to}/ndk/21.2.6472646/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi16-clang
CXX={path to}/ndk/21.2.6472646/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi16-clang++
CGO_ENABLED=1
GOARM=7