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

Android Linking Error when using audio module #4322

Closed
2 tasks done
BogdanTheGeek opened this issue Oct 16, 2023 · 3 comments
Closed
2 tasks done

Android Linking Error when using audio module #4322

BogdanTheGeek opened this issue Oct 16, 2023 · 3 comments
Labels
unverified A bug that has been reported but not verified

Comments

@BogdanTheGeek
Copy link

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

Trying to use fyne together with github.com/faiface/beep causes a linking issue when packaging for android (works fine for native)

I have seen #2064, which looks similar, but after trying the a few older version of the NDK, cleaning the build cache in between, I still get the same result.
NDK version tried:

  • 20.1.5948944
  • 21.4.7075529
  • 23.0.7599858
  • 26.1.10909125

My assumption is that both beep(based on oto) and fyne define the following symbols. This could also be an upstream gomobile bug/limitation.

Here is an error log (I have removed duplicate details):

go build -buildmode=c-shared -o /var/folders/00/z7nqwngs2psft9hb9lws8svm0000gn/T/fyne-work-646537007/lib/armeabi-v7a/libfyne_app.so fyne-app failed: exit status 1
# fyne-app
/opt/homebrew/Cellar/go/1.20.4/libexec/pkg/tool/darwin_arm64/link: running /Users/bogdan/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi21-clang failed: exit status 1
ld.lld: error: duplicate symbol: setCurrentContext
>>> defined at _cgo_export.c:25
>>>            /var/folders/00/z7nqwngs2psft9hb9lws8svm0000gn/T/go-link-647208879/000020.o:(setCurrentContext)
>>> defined at _cgo_export.c:25
>>>            /var/folders/00/z7nqwngs2psft9hb9lws8svm0000gn/T/go-link-647208879/000039.o:(.text+0x0)

ld.lld: error: duplicate symbol: callMain
ld.lld: error: duplicate symbol: onStart
ld.lld: error: duplicate symbol: onResume
ld.lld: error: duplicate symbol: onSaveInstanceState
ld.lld: error: duplicate symbol: onPause
ld.lld: error: duplicate symbol: onStop
ld.lld: error: duplicate symbol: onCreate
ld.lld: error: duplicate symbol: onDestroy
ld.lld: error: duplicate symbol: onWindowFocusChanged
ld.lld: error: duplicate symbol: onNativeWindowCreated
ld.lld: error: duplicate symbol: onNativeWindowRedrawNeeded
ld.lld: error: duplicate symbol: onNativeWindowDestroyed
ld.lld: error: duplicate symbol: onInputQueueCreated
ld.lld: error: duplicate symbol: onInputQueueDestroyed
ld.lld: error: duplicate symbol: onContentRectChanged
ld.lld: error: duplicate symbol: onConfigurationChanged
ld.lld: error: duplicate symbol: onLowMemory
ld.lld: error: duplicate symbol: JNI_OnLoad
ld.lld: error: duplicate symbol: ANativeActivity_onCreate

ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)

How to reproduce

fyne package -os android -appID com.example.myapp

Screenshots

No response

Example code

package main

import (
	"fmt"
	"log"
	"net/http"
	"sync"
	"time"

	"github.com/faiface/beep"
	"github.com/faiface/beep/mp3"
	"github.com/faiface/beep/speaker"

	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
)

func PlaySound() {
	f, err := http.Get("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Body.Close()

	streamer, format, err := mp3.Decode(f.Body)
	if err != nil {
		log.Fatal(err)
	}
	defer streamer.Close()

	speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))

	var wg sync.WaitGroup
	wg.Add(1)

	fmt.Println("Playing sound")

	speaker.Play(beep.Seq(streamer, beep.Callback(func() {
		wg.Done()
	})))

	wg.Wait()

	fmt.Println("Done playing sound")
}

func main() {
	a := app.New()
	a.Settings().SetTheme(theme.LightTheme())
	w := a.NewWindow("Clock")

	play := widget.NewButton("play", func() {
		go PlaySound()
	})

	w.SetContent(play)
	w.ShowAndRun()
}

Fyne version

2.4.1

Go compiler version

1.20.4

Operating system and version

macOS Sonoma M1

Additional Information

No response

@BogdanTheGeek BogdanTheGeek added the unverified A bug that has been reported but not verified label Oct 16, 2023
@andydotxyz
Copy link
Member

Maybe your app (or one of the deps) has brought in a gomobile dependency? You can't have both gomobile and Fyne in your app.

@BogdanTheGeek
Copy link
Author

github.com/gopxl/beep latest release as of today use a very old version on oto that includes gomobile. Upgrading to the main branch fixes the issue.

go get 'github.com/gopxl/beep@main'

@andydotxyz
Copy link
Member

For anyone that isn't able to remove the gomobile dependency from your project (usually due to transitive dependencies) there is another solution!

Fyne has a gomobile-bridge project that maps the gomobile APIs into a Fyne runtime: https://github.com/fyne-io/gomobile-bridge

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

2 participants