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: gomobile bind does not support vendor #34181

Open
Student414 opened this issue Sep 9, 2019 · 4 comments
Open

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

Student414 opened this issue Sep 9, 2019 · 4 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

@Student414
Copy link

Student414 commented Sep 9, 2019

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?

  • go get github.com/fatedier/frp
  • vi {GOPATH}/github.com/fatedier/frp/cmd/frpc/sub/export.go
package sub

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)))))
@Student414 Student414 changed the title mobile: gomobile bind mobile: gomobile bind cannot support vendor Sep 9, 2019
@smasher164 smasher164 changed the title mobile: gomobile bind cannot support vendor x/mobile: gomobile bind does not support vendor Sep 9, 2019
@gopherbot gopherbot added this to the Unreleased milestone Sep 9, 2019
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Sep 9, 2019
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 10, 2019
@x1ddos
Copy link

x1ddos commented Jun 7, 2020

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
Copy link

kordax commented Feb 11, 2022

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
Copy link

TTy32 commented Jul 18, 2022

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

@TTy32
Copy link

TTy32 commented Jul 26, 2022

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

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

6 participants