Getting 'missing module declaration' when using gomobile bind even if the go.mod exists and module is declared

113 Views Asked by At

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:

  1. go: 1.22.0 darwin/arm64
  2. gomobile: v0.0.0-20240213143359-d1f7d3436075
  3. v2ray-core: https://github.com/v2fly/v2ray-core commit 458db39
  4. 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?

1

There are 1 best solutions below

0
Simenons On

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 gomobile was stuck when writing to temporary go.mod files is still unknown. (Maybe due to more than one package to share the only module under the root directory?)