golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.38k stars 17.71k forks source link

x/mobile: gomobile bind does not support vendor #34181

Open Student414 opened 5 years ago

Student414 commented 5 years ago

What version of Go are you using (go version)?

go version go1.13 windows/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Wang\AppData\Local\go-build
set GOENV=C:\Users\Wang\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\Work\go\gopath
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\Work\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Work\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\Work\go\gopath\src\github.com\fatedier\frp\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Wang\AppData\Local\Temp\go-build704107050=/tmp/go-build -gno-record-gcc-switches

What did you do?

import ( "time" "math/rand"

_ "github.com/fatedier/frp/assets/frpc/statik"

"github.com/fatedier/golib/crypto"

) // I want to export this function only func Start(filePath string) { crypto.DefaultSalt = "frp" rand.Seed(time.Now().UnixNano())

runClient(filePath)

}

open terminal
`gomobile bind -target android github.com/fatedier/frp/cmd/frpc/sub`

### What did you expect to see?
gomobile create a .aar and .jar file

### What did you see instead?

gomobile: D:\Work\go\gopath\bin\gobind.exe -lang=go,java -outdir=C:\Users\Wang\AppData\Local\Temp\gomobile-work-225577183 github.com/fatedier/frp/cmd/frpc/sub failed: exit status 1 type-checking package "github.com/fatedier/frp/cmd/frpc/sub" failed (D:\Work\go\gopath\src\github.com\fatedier\frp\cmd\frpc\sub\http.go:22:2: could not import github.com/spf13/cobra (type-checking package "github.com/spf13/cobra" failed (D:\Work\go\gopath\pkg\mod\github.com\spf13\cobra@v0.0.3\bash_completions.go:11:2: could not import github.com/spf13/pflag (cannot find package "github.com/spf13/pflag" in any of: D:\Work\go\src\github.com\spf13\pflag (from $GOROOT) D:\Work\go\gopath\src\github.com\spf13\pflag (from $GOPATH)))))

x1ddos commented 4 years ago

Any update here? gomobile bind -mod vendor says "flag provided but not defined: -mod". Without the flag, it always downloads packages ignoring vendor/ dir just like with a regular build.

This is on go1.14.

kordax commented 2 years ago

Hi, any update on this?

gobind -lang=go,java -outdir=/tmp/gomobile-work-1386653115 -javapkg=net.isoftservices.client ./src/game/android
unable to import bind: [-: cannot find package "." in:
    /home/kordax/Projects/maxbet/octopus/vendor/golang.org/x/mobile/bind]
unable to import bind: [-: cannot find package "." in:
    /home/kordax/Projects/maxbet/octopus/vendor/golang.org/x/mobile/bind]
unable to import bind: [-: cannot find package "." in:
    /home/kordax/Projects/maxbet/octopus/vendor/golang.org/x/mobile/bind]
"golang.org/x/mobile/bind" is not found; run go get golang.org/x/mobile/bind: [-: cannot find package "." in:
    /home/kordax/Projects/maxbet/octopus/vendor/golang.org/x/mobile/bind]
TTy32 commented 2 years ago

I get the same error using vendor/ / go version go1.18.3 linux/amd64

TTy32 commented 2 years ago

Some further digging, starting from scratch:

From: https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile

$ go install golang.org/x/mobile/cmd/gomobile@latest
$ export PATH=$PATH:/home/user/go/bin
$ gomobile init
$ gomobile version
gomobile version unknown: cannot test gomobile binary: exit status 1, no required module provides package
golang.org/x/mobile/cmd/gomobile: go.mod file not found in current directory or any parent directory; 
see 'go help modules'

Ok, so in a module:

$ mkdir test ; cd test ; go mod init test.com
go: creating new go.mod: module test.com 

And: git init ; echo "test" > readme.md ; git add readme.md ; git commit -m "Initial"

$ go mobile version

gomobile version unknown: cannot test gomobile binary: exit status 1, no required module provides package
golang.org/x/mobile/cmd/gomobile; to add it:

    go get golang.org/x/mobile/cmd/gomobile

Run go get:

$ go get golang.org/x/mobile/cmd/gomobile                                               
go: added golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105      
go: added golang.org/x/mod v0.4.2                                     
go: added golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e         
go: added golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098     
go: added golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1     
$ go mod tidy
go: warning: "all" matched no packages

$ gomobile version

gomobile version unknown: cannot test gomobile binary: exit status 1, no required module provides package
golang.org/x/mobile/cmd/gomobile; to add it:

        go get golang.org/x/mobile/cmd/gomobile

Ok, try example:

Download https://cs.opensource.google/go/x/mobile/+/aaac322e:example/basic/main.go

$ go mod tidy
go: downloading golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56  
go: downloading golang.org/x/image v0.0.0-20190802002840-cff245a6509b

$ go mod vendor
$ gomobile version

gomobile version unknown: cannot test gomobile binary: exit status 1, cannot find package "." in:
        /home/user/test/vendor/golang.org/x/mobile/cmd/gomobile

Ok, apparently golang.org/x/mobile/cmd/gomobile is never added to go.mod since not being a dependency. Force dependency by adding package to main.go:

    _ "golang.org/x/mobile/cmd/gomobile"

Try again:

$ go mod tidy
$ go mod vendor
$ gomobile version

gomobile version unknown: binary is out of date, re-install it

Here is when the error is triggered in go mobile source: https://github.com/golang/mobile/blob/8578da9835fd365e78a6e63048c103b27a53a82c/cmd/gomobile/version.go#L46

Apparently go list -f {{.Stale}} golang.org/x/mobile/cmd/gomobile should return false, but it returns true in our test module:

$ go list -f {{.Stale}} golang.org/x/mobile/cmd/gomobile
true

If we use StaleReason:

$ go list -f {{.StaleReason}} golang.org/x/mobile/cmd/gomobile

We get:

stale dependency: golang.org/x/mobile/internal/sdkpath

On other test repo we get the same reason, just a different dependency path (e.g. stale dependency: cgo)

My current knowledge of golang doesn't go as far as to know how to investigate this further. Hope someone else can pick this up.

go version go1.18.3 linux/amd64

benma commented 5 months ago

Can someone from the gomobile team comment? I still cannot use gomobile with vendoring and go modules. I am using GO111MODULE=off as a workaround, which is not great.