I'm trying to use gomobile to compile the v2ray-core to a xcframework. The commands are as follows:
gomobile init
go mod tidy -v
go get -d golang.org/x/mobile/cmd/gomobile
gomobile bind -v -target=ios -o v2Ray.xcframework -ldflags='-s -w' ./
Then I got the errors like:
write /var/folders/cr/1p6sw8z51sjgf4t6v3k1v12w0000gn/T/gomobile-work-1717835187/ios/src-arm64/go.mod
go: error reading go.mod: missing module declaration. To specify the module path:
go mod edit -module=example.com/mod
Version Info:
- go: 1.22.0 darwin/arm64
- gomobile: v0.0.0-20240213143359-d1f7d3436075
- v2ray-core: https://github.com/v2fly/v2ray-core commit 458db39
- xcode: 15.2
I've checked that there is a go.mod file under the root directory and the module declaration exists: module github.com/v2fly/v2ray-core/v5. I also checked the temporary go.mod file that gomobile wrote to, and I found that it was empty. Then I was stuck here.
Could you explain why gomobile fails to write to the temporary go.mod file? What is this file used for?
It seems that I was trying to bind all those built-in functions under the root directory as a library. The 'right' thing to do is to create a importable entry for the whole project, as described in https://github.com/v2fly/v2ray-core/issues/1702. However, the reason why
gomobilewas stuck when writing to temporarygo.modfiles is still unknown. (Maybe due to more than one package to share the only module under the root directory?)