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

x/mobile: Error running gomobile init Go 1.17 #50994

Closed
morningsend opened this issue Feb 3, 2022 · 13 comments
Closed

x/mobile: Error running gomobile init Go 1.17 #50994

morningsend opened this issue Feb 3, 2022 · 13 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@morningsend
Copy link

morningsend commented Feb 3, 2022

After recent changes with the way Go modules works in Go 1.16 and Go 1.17, we are seeing issues with gomobile.

$ go install golang.org/x/mobile/cmd/gomobile@latest
$ gomobile init
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
go install: version is required when current directory is not in a module
        Try 'go install golang.org/x/mobile/cmd/gobind@latest' to install the latest version

The line codde that related to this issue is:
https://github.com/golang/mobile/blob/master/cmd/gomobile/init.go#L81

i.e., installing a command now requires a version such as

go install golang.org/x/mobile/cmd/gobind@latest

If we try running gomobile init from a go module we also get an error:

$ mkdir -p /tmp/mobile_test
$ cd /tmp/mobile_test
$ go mod init mobile_test
$ go install golang.org/x/mobile/cmd/gomobile@latest
$ gomobile init
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
no required module provides package golang.org/x/mobile/cmd/gobind; to add it:
        go get golang.org/x/mobile/cmd/gobind

Go version:

$ go version
go version go1.17.6 linux/amd64

Go env:

# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/go/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/mobile_test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3067796960=/tmp/go-build -gno-record-gcc-switches"
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Feb 3, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 3, 2022
@kordax
Copy link

kordax commented Feb 4, 2022

Same issue here:
go version go1.17.6 linux/amd64
go install -v golang.org/x/mobile/cmd/gomobile@latest does nothing:
$ grep gomobile go.mod | wc -c 0

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 4, 2022
@zhangqibo
Copy link

I got the same problem.
go version go1.17.6 windows/amd64

@changkun
Copy link
Member

changkun commented Feb 7, 2022

As suggested, go get golang.org/x/mobile/cmd/gobind can solve the issue.

@morningsend
Copy link
Author

As suggested, go get golang.org/x/mobile/cmd/gobind can solve the issue.

@changkun Do you suggest we create a dummy go module and run go get? Otherwise go prints the following warning:

$ go get golang.org/x/mobile/cmd/gobind
go: downloading golang.org/x/mobile v0.0.0-20220112015953-858099ff7816
go: downloading golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098
go get: installing executables with 'go get' in module mode is deprecated.
	Use 'go install pkg@version' instead.
	For more information, see https://golang.org/doc/go-get-install-deprecation
	or run 'go help get' or 'go help install'.

@changkun
Copy link
Member

changkun commented Feb 8, 2022

I think so. As far as I understood the issue, you are executing and running go install inside a go module. After my attempt to reproduce the issue, when receiving this error:

$ gomobile init
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
no required module provides package golang.org/x/mobile/cmd/gobind; to add it:
        go get golang.org/x/mobile/cmd/gobind

We can simply follow the suggestion go get golang.org/x/mobile/cmd/gobind to get rid of the error. Then gomobile init works smoothly.

@kordax
Copy link

kordax commented Feb 8, 2022

I think so. As far as I understood the issue, you are executing and running go install inside a go module. After my attempt to reproduce the issue, when receiving this error:

$ gomobile init
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
no required module provides package golang.org/x/mobile/cmd/gobind; to add it:
        go get golang.org/x/mobile/cmd/gobind

We can simply follow the suggestion go get golang.org/x/mobile/cmd/gobind to get rid of the error. Then gomobile init works smoothly.

It won't work with vendoring.

$ gomobile init
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
cannot find package "." in:
/home/kordax/Projects/maxbet/ebiten-client/vendor/golang.org/x/mobile/cmd/gobind

@kordax
Copy link

kordax commented Feb 8, 2022

Well, vendor mode is probably a different issue, without vendor mode "go get golang.org/x/mobile/cmd/gobind" works fine.

@changkun
Copy link
Member

changkun commented Feb 8, 2022

@kordax You are right that vendor mode is a different issue. If your vendor folder does not contain golang.org/x/mobile/cmd/gobind, then it certainly cannot find such a package and throw an error.

@kordax
Copy link

kordax commented Feb 8, 2022

@changkun well, the vendor folder does not contain Gobind because it doesn't work properly with go mod vendor and is not explicitly mentioned I guess.

@morningsend
Copy link
Author

Would this snippet fix the issue?

@@ -78,7 +78,7 @@ func runInit(cmd *command) error {
        }()
 
        // Make sure gobind is up to date.
-       if err := goInstall([]string{"golang.org/x/mobile/cmd/gobind"}, nil); err != nil {
+       if err := goInstall([]string{"golang.org/x/mobile/cmd/gobind@latest"}, nil); err != nil {
                return err
        }
 

@changkun
Copy link
Member

changkun commented Feb 9, 2022

I think so. Feel free to send a CL for that :)

@morningsend
Copy link
Author

I think so. Feel free to send a CL for that :)

Thanks, will do so

morningsend added a commit to morningsend/mobile that referenced this issue Feb 9, 2022
Go install requires a version to be provided after the package name.
gomobile init command is updated to reflect this new requirement

Fixes golang/go#50994
@gopherbot
Copy link

Change https://go.dev/cl/384414 mentions this issue: cmd/gomobile: add missing latest tag to gobind

jakubelixxir pushed a commit to xxfoundation/elixxir-client that referenced this issue Jan 26, 2023
jakubelixxir pushed a commit to xxfoundation/elixxir-client that referenced this issue Jan 26, 2023
@golang golang locked and limited conversation to collaborators Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants