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: does not work with Go 1.22 if a vendor folder is present, even with the GO111MODULE=off workaround #67927

Open
benma opened this issue Jun 11, 2024 · 3 comments
Labels
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

@benma
Copy link

benma commented Jun 11, 2024

Go version

go1.22.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/opt/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/opt/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/go_dist/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go_dist/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/mobiletest/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2991625483=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Using a dummy main.go:

main.go 
package mobiletest

func Foo() {
}
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
go mod init mobiletest
go mod vendor
gomobile bind -a -target android .
go get golang.org/x/mobile/bind

What did you see happen?

The above fails with:

"golang.org/x/mobile/bind" is not found; run go get golang.org/x/mobile/bind: no Go package in golang.org/x/mobile/bind                                                                                            

As a workaround, before Go1.22, one could install mobile/bind to $GOPATH and use gomobile bind without modules to side-step this issue completely:

GO111MODULE=off go get -u golang.org/x/mobile/cmd/gomobile
GO111MODULE=off gomobile bind -a -target android .

Since GO 1.22 however, go get is not allowed anymore outside of modules.

What did you expect to see?

No error running gomobile bind.

gomobile bind seems to be unworkable using Go 1.22 when a vendor folder is present. The only workaround seems to be to delete the vendor folder before using gomobile bind.

Related: #34181, but the GO111MODULE=off workaround does not work anymore as of Go 1.22.

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jun 11, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jun 11, 2024
@gabyhelp
Copy link

@benma
Copy link
Author

benma commented Jun 11, 2024

Another thing I tried is #43736 (comment):

Import _ "golang.org/x/mobile/cmd/gobind", then go mod vendor.

But then gomobile bind seems to invoke go mod tidy on a package that is not module aware and results in:

PWD=$WORK/src-android-386 GOMODCACHE=$GOPATH/pkg/mod GOOS=android GOARCH=386 CC=$ANDROID_HOME/ndk/21.2.6472646/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android16-clang CXX=$ANDROID_HOME/ndk/21.2.6472646/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android16-clang++ CGO_ENABLED=1 GOPATH=$WORK:$GOPATH go mod tidy
rm -r -f "$WORK"
gomobile: go mod tidy failed: exit status 1
go: error reading go.mod: missing module declaration. To specify the module path:
        go mod edit -module=example.com/mod

@benma benma changed the title x/mobile: does not work with Go 1.22 if a vendor module is present, even with the GO111MODULE=off workaround x/mobile: does not work with Go 1.22 if a vendor folder is present, even with the GO111MODULE=off workaround Jun 11, 2024
@prattmic prattmic added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 12, 2024
@hyangah
Copy link
Contributor

hyangah commented Jun 12, 2024

Can you try to manually list the golang.org/x/mobild/bind/* packages in an ignored file, and run go mod tidy & go mod vendor, so the necessary dependencies are vendored if vendoring is required?

//go:build mobilex
// +build mobilex

package mobiletest

import (
	_ "golang.org/x/mobile/bind"
	_ "golang.org/x/mobile/bind/java"
        _ "golang.org/x/mobile/bind/objc"
)

Keeping up with all the Go, Android, Apple toolchains changes is a non-trivial task. Unfortunately, there is nobody actively working on x/mobile as of today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

No branches or pull requests

5 participants