Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging an android fyne app that uses the torrent library "github.com/anacrolix/torrent" #3641

Closed
2 tasks done
vboehr opened this issue Feb 8, 2023 · 12 comments
Closed
2 tasks done
Labels
unverified A bug that has been reported but not verified

Comments

@vboehr
Copy link

vboehr commented Feb 8, 2023

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

I am trying to package an android fyne app that uses the following torrent library:
github.com/anacrolix/torrent

Yet after installing the app on android and running it I get a black screen and app stops.

How to reproduce

create a new go mod
go mod init fynetorrentguiapp

go get fyne.io/fyne/v2

go get github.com/anacrolix/torrent

touch main.go

add the example code include below

package the app as follow:
./fyne-cmd package -os android -appID com.fynetorrentguiapp.myapp

install the app on android and run it.

Screenshots

No response

Example code

'''go
package main
import (
"log"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/widget"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/canvas"
"image/color"
"time"
"fmt"
"github.com/anacrolix/torrent"
)
var mainapp fyne.App
var AppLocation string
var MainTorrent string//magnet
var MainFile string//filepath
var AppIsClosing bool
func main() {
mainapp= app.New()
AppIsClosing=false
AppLocation=mainapp.Storage().RootURI().String()
fmt.Println("AppLocation :",AppLocation)
mainwin := mainapp.NewWindow("wetorrent")
mainwin.Resize(fyne.NewSize(400, 710))
go initmainclient()
tabs := container.NewAppTabs(
container.NewTabItem("Home", homeScreen(mainwin)),
)
tabs.SetTabLocation(container.TabLocationTop)
mainwin.SetContent(tabs)
mainwin.ShowAndRun()
AppIsClosing=true
}
func homeScreen(win fyne.Window) fyne.CanvasObject {
data := binding.BindStringList(
//&[]string{"Item 1", "Item 2", "Item 3"},
&[]string{},
)
list := widget.NewListWithData(data,
func() fyne.CanvasObject {
return widget.NewLabel("template")
},
func(i binding.DataItem, o fyne.CanvasObject) {
o.(*widget.Label).Bind(i.(binding.String))
})
text := canvas.NewText("Text Object"+AppLocation, color.Black)
add := widget.NewButton("Open New Webapp Tab", func() {
//val := fmt.Sprintf("Item %d", data.Length()+1)
//data.Append(val)
fmt.Println("coool")
})
return container.NewBorder( text,add, nil, nil, list)
}
var mainclient * torrent.Client
func initmainclient() {
cfg := torrent.NewDefaultClientConfig()
//cfg.Seed = true
cfg.DataDir=AppLocation//
//cfg.NoDHT = true
//cfg.DisableTCP = true
//cfg.DisableUTP = true
//cfg.DisableAggressiveUpload = false
//cfg.DisableWebtorrent = false
//cfg.DisableWebseeds = false
var err error
mainclient, err = torrent.NewClient(cfg)
if err != nil {
log.Print("new torrent client: %w", err)
return //fmt.Errorf("new torrent client: %w", err)
}
log.Print("new torrent client INITIATED")
defer mainclient.Close()
for {
if AppIsClosing {
log.Print("closing mainclient")
break
}
time.Sleep(1 * time.Second)
}
//
}
''''

Fyne version

v2.3.0

Go compiler version

go1.20 linux/amd64

Operating system

Linux

Operating system version

Ubuntu 18.04.6 LTS (Bionic Beaver)

Additional Information

./fyne-cmd env

Go module info

cli_version="(devel)"
go_mod="true"
go_path="false"
imported="true"
path="***********"
version="v2.3.0"

Go version info

version="go1.20 linux/amd64"

Go environment info

CGO_ENABLED="1"
GO111MODULE=""
GOARCH="amd64"
GOOS="linux"

OS info

architecture="x86_64"
home_url="https://www.ubuntu.com/"
kernel="Linux 5.4.0-137-generic #154~18.04.1-Ubuntu SMP Tue Jan 10 16:58:20 UTC 2023"
name="Ubuntu"
version="18.04.6 LTS (Bionic Beaver)"

@vboehr vboehr added the unverified A bug that has been reported but not verified label Feb 8, 2023
@vboehr vboehr changed the title Building a fyne app that uses the torrent library "github.com/anacrolix/torrent" Packaging an android fyne app that uses the torrent library "github.com/anacrolix/torrent" Feb 8, 2023
@andydotxyz
Copy link
Member

Does the library support android? I'm not sure this ticket belongs in the toolkit bug tracker...

@vboehr
Copy link
Author

vboehr commented Feb 8, 2023

Apparently the library does run on android:
anacrolix/torrent#808

@Jacalz
Copy link
Member

Jacalz commented Feb 8, 2023

If so, would you mind creating a minimal example application to make it easier to test? Also, FYI, I agree with @andydotxyz that this might not be the right place to put it. Does not necessarily seem to be a Fyne issue.

@andydotxyz
Copy link
Member

There is a high chance your code is initialising the torrent library to use file storage you don't have access to.
As you'll see in our docs the general Go file libraries won't necessarily work and we encourage our "storage" package for the cross-platform guarantees.

@vboehr
Copy link
Author

vboehr commented Feb 18, 2023

I used "adb logcat" to get the runtime error and I got +1
java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
Screenshot from 2023-02-17 21-48-45

@vboehr
Copy link
Author

vboehr commented Feb 18, 2023

I asked chatgpt to explain this runtime error and here its answer:

CHATGPT answer:
Based on the error message you provided, it seems that the libc++_shared.so library is missing. This library is required by the libwetorrent_rebirth.so library, which is used by your app.

To fix this issue, you should make sure that you have included the libc++_shared.so library in your project and that it is being properly loaded by your app.

Here are some steps you can try to resolve this issue:

Check that you have included the libc++_shared.so library in your project. You can do this by looking for the library in your project's libs directory. If the library is missing, you may need to download it from the Android NDK and include it in your project.

If the libc++_shared.so library is present in your project, you should check that it is being properly loaded by your app. You can do this by checking your app's Android.mk or CMakeLists.txt file to ensure that the library is included in the LOCAL_LDLIBS variable.

If you are still having issues, you may want to try building your app with a different version of the Android NDK, as the version you are using may not be compatible with your project.

I hope this helps! Let me know if you have any further questions or concerns.

@vboehr
Copy link
Author

vboehr commented Feb 22, 2023

Based on anacrolix recommendation described here (https://github.com/anacrolix/torrent/issues/809). I tried disabling the part that uses c++ (which is called "libutp") with the following command:

./fyne-cmd package -os android -appID com.test.myapp -icon ./Icons/appicon.png --tags=disable_libutp

Yet I still have the same error.

Is my command correctly passing tags to fyne?

@Bluebugs
Copy link
Contributor

I think you have found a short coming of our iOS and Android build. I don't think we are currently passing the tags when building for those mobile OS. I will do a PR to cover this shortly.

In the mean time, you can verify, if you are on Linux, that this will do what you want. You can build for Linux and then use the ldd to list all the library used by your application. If there is no reference to that shared C++ library, it means that with a fix for propagating tags when building for Android and iOS, you will be good.

@Bluebugs
Copy link
Contributor

If you can also test the branch of PR #3674 by doing a go install fyne.io/fyne/cmd/fyne@e33124d67edd0cda23b2b1745fb73dff0e1be5c5 and then using the newly installed fyne command to build for android.

@Bluebugs
Copy link
Contributor

It is now in develop, so you can just check after doing go install fyne.io/fyne/cmd/fyne@develop.

@vboehr
Copy link
Author

vboehr commented Feb 23, 2023

Thanks for the help provided. I tested "fyne.io/fyne/cmd/fyne@develop" and now it passing "disable_libutp" tag to the build, which solved the issue. Now I can use "anacrolix/torrent" in a fyne app !

Thanks again !

@andydotxyz
Copy link
Member

Fantastic, thanks for checking :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

4 participants