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 is failing with latest version [+cafc553] of gomobile #33859

Closed
jay11ca39 opened this issue Aug 27, 2019 · 35 comments
Closed

Comments

@jay11ca39
Copy link

@jay11ca39 jay11ca39 commented Aug 27, 2019

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

$ go version: go1.12.4 linux/amd64

$ go mobile version: 
gomobile version +cafc553 Mon Aug 26 17:01:11 2019 +0000 (android); androidSDK=/home/--/Android/Sdk/platforms/android-28

Does this issue reproduce with the latest release?

Yes, the issue is produced only on the latest gomobile version.

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

go env Output
$ go env

GOARCH="amd64"
GOBIN="/usr/local/go"
GOCACHE="/home/--/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="My Go path"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build242944229=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Trying to generate the java binding for my go file:
Error:

gomobile bind -o ~/test.aar -target=android -androidapi=23 test || exit 1
gomobile: $GOPATH/bin/gobind -lang=go,java -outdir=/tmp/gomobile-work-628614164 test failed: exit status 1
2019/08/27 09:51:37 go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags -- test]: exit status 2: # runtime/cgo
gcc_android.c:6:25: fatal error: android/log.h: No such file or directory
compilation terminated.

What did you see instead?

Error in generating the java binding.

Note: Before updating the gomobile same code was building.

@gopherbot gopherbot added this to the Unreleased milestone Aug 27, 2019
@gopherbot gopherbot added the mobile label Aug 27, 2019
@jay11ca39

This comment has been minimized.

Copy link
Author

@jay11ca39 jay11ca39 commented Aug 27, 2019

Hello @hajimehoshi ,
Yesterday your patch got merged:
golang/mobile@cafc553
Before that, gomobile bind was working.

Can you please please let me know, what update I have to make to gobind command ?

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 27, 2019

Hi,

I'm not sure your question, but my last patch should fix some bugs and gobind should work (as long as go module is not used).

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 27, 2019

Could you try gomobile with GO111MODULE=off?

@jay11ca39

This comment has been minimized.

Copy link
Author

@jay11ca39 jay11ca39 commented Aug 27, 2019

@hajimehoshi ,

Now, I removed the gomobile and gobind from my system completely. (src and bin folder)

Now, I tried freshly to do:
go get golang.org/x/mobile/cmd/gomobile

But following error is coming:

package golang.org/x/mobile/cmd/gomobile: cannot find package "golang.org/x/mobile/cmd/gomobile" in any of:
/usr/local/go/src/golang.org/x/mobile/cmd/gomobile (from $GOROOT)
/home/jay/go/src/golang.org/x/mobile/cmd/gomobile (from $GOPATH)

Any idea ?

@torbenschinke

This comment has been minimized.

Copy link

@torbenschinke torbenschinke commented Aug 27, 2019

@jay11ca39 You can try the following order, to see if that helps (still GO111MODULE=off):

go get golang.org/x/mobile/cmd/gobind
go get golang.org/x/mobile/cmd/gomobile
gomobile init
@jay11ca39

This comment has been minimized.

Copy link
Author

@jay11ca39 jay11ca39 commented Aug 27, 2019

@torbenschinke
Thanks for your reply..

I tried the suggested way, but it is also giving the same error:
go get golang.org/x/mobile/cmd/gobind

package golang.org/x/mobile/cmd/gobind: cannot find package "golang.org/x/mobile/cmd/gobind" in any of:
/usr/local/go/src/golang.org/x/mobile/cmd/gobind (from $GOROOT)
/home/jay/go/src/golang.org/x/mobile/cmd/gobind (from $GOPATH)

I have one basic query regarding: GO111MODULE=off
How to make sure it is off ?

Is it a flag we have to give while doing go get ?
For example:

GO111MODULE=off go get golang.org/x/mobile/cmd/gobind

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 27, 2019

Is it a flag we have to give while doing go get ?

It is safe to give GO111MODULE=off explicitly when go-getting gomobile/gobind. My guess is that you did go-get with modules. Then try:

GO111MODULE=off go get golang.org/x/mobile/cmd/gobind
GO111MODULE=off go get golang.org/x/mobile/cmd/gomobile
gomobile init

EDIT: module-aware go-get also installs binaries under $GOPATH/bin, so golang.org/x/mobile/cmd/gobind should work. 🤔

@jay11ca39

This comment has been minimized.

Copy link
Author

@jay11ca39 jay11ca39 commented Aug 27, 2019

I am using gomobile for couple of months.. I used to give:

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

As you see above commands, I do not have use GO111MODULE flag.
But today when I am tried it is failing I am not sure what is the cause..

This issue is raised for gobind on latest gomobile version.
but now it became go get issue. :(

Edit:
@hajimehoshi
You are correct, previously I did not use GO111MODULE=off flag, then as suggested by you, I tried with that flag. But now, I think it is failing to do go get on other packages as well.
For example: go get github.com/axw/gocov/gocov is also failing.

How can I fix this go get ?

@hsjoberg

This comment has been minimized.

Copy link

@hsjoberg hsjoberg commented Aug 27, 2019

I have the same issue, running inside a docker (debian:stretch-slim).
If it would be of any help, you can try it out here: https://hub.docker.com/r/blixtwallet/blixtwallet/
This is the Dockerfile: https://github.com/hsjoberg/blixt-wallet/blob/35a904cf1f9c6a5da74ecdd4e09dbf5ee6fae24b/Dockerfile

@rayvbr

This comment has been minimized.

Copy link

@rayvbr rayvbr commented Aug 27, 2019

We're having the same issue (gcc_android.c:6:25: fatal error: android/log.h: No such file or directory) @jay11ca39 initially reported. I can also confirm the problem started once golang/mobile@cafc553 was merged. If I revert that commit, all is well

Edit: note that we're not using Go modules

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

I can also confirm the problem started once golang/mobile@cafc553 was merged.

I was wondering if the previous commit golang/mobile@30c70e3 worked on your environment.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

I could not reproduce the issue. The latest gomobile worked on my MacBook Pro:

$ gomobile version
gomobile version +cafc553 Mon Aug 26 17:01:11 2019 +0000 (android,ios); androidSDK=/Users/hajimehoshi/Library/Android/sdk/platforms/android-28
@jay11ca39

This comment has been minimized.

Copy link
Author

@jay11ca39 jay11ca39 commented Aug 28, 2019

Hello @rayvbr ,
How did you revert to the old commit ?

Are you building gomobile from source, I mean cloning and building or
Is there is any option in go get to take a specific version ?

cc @hajimehoshi

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

@jay11ca39

You can use any version of gomobile by using git:

cd $GOPATH/go/src/golang.org/x/mobile
git checkout [version]
go install ./cmd/...
@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

I had the same issue.
After reverting back to 30c70e3810e97d051f18b66d59ae242540c0c391 everything works again.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

OK I think I found the solution: could you try

go get -u golang.org/x/tools

? https://go-review.googlesource.com/c/tools/+/190339 should be the necessary change.

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

OK I think I found the solution: could you try

go get -u golang.org/x/tools

? https://go-review.googlesource.com/c/tools/+/190339 should be the necessary change.

I tried this (with modules enabled and disabled) but that doesn't seem to work.

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

Updating all tools with go get -u golang.org/x/tools/... also doesn't help.

@torbenschinke

This comment has been minimized.

Copy link

@torbenschinke torbenschinke commented Aug 28, 2019

I can confirm, that reverting back to 30c70... also worked for us

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

Thanks. It looks like this happens when the default driver is not used. I am not familiar with drivers...

@HeavyHorst do you have gopackagesdriver command in $PATH, or did you specify $GOPACKAGESDRIVER?

@matloob If an external driver in go/packages is used, the fix https://go-review.googlesource.com/c/tools/+/190339 is not applied. Is my understanding correct? I was wondering if there is a workaround.

CC @hyangah

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

@HeavyHorst do you have gopackagesdriver command in $PATH, or did you specify $GOPACKAGESDRIVER?

No, neither one nor the other.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

Hmm, thanks.

Updating all tools with go get -u golang.org/x/tools/... also doesn't help.

Could you tell me the Git hash of $GOPATH/src/golang.org/x/tools? If you did go get with enabling Go modules, this might not be updated. Sorry you said you did with and without modules...

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

Thanks for investigating.

The hash is: b29f5f60c37a1dd56e6942c2717b85b976e4a592

Let me know if you need anything else.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

@HeavyHorst

Thanks! Could you try

cd $GOPATH/src/golang.org/x/mobile
GOPACKAGESDRIVER=off GO111MODULE=off go test -v -run=TestGobind/Go-Cgopkg -count=1 ./cmd/gobind

and tell me the result?

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

GOPACKAGESDRIVER=off GO111MODULE=off go test -v -run=TestGobind/Go-Cgopkg -count=1 ./cmd/gobind
=== RUN   TestGobind
=== RUN   TestGobind/Go-Cgopkg
--- FAIL: TestGobind (0.28s)
    --- FAIL: TestGobind/Go-Cgopkg (0.28s)
        gobind_test.go:82: gobind -lang go,java,objc golang.org/x/mobile/bind/testdata/cgopkg failed: exit status 1: 2019/08/28 12:52:09 go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags  -- golang.org/x/mobile/bind/testdata/cgopkg]: exit status 2: # runtime/cgo
            gcc_android.c:6:10: schwerwiegender Fehler: android/log.h: No such file or directory
                6 | #include <android/log.h>
                  |          ^~~~~~~~~~~~~~~
            Kompilierung beendet.

FAIL
FAIL    golang.org/x/mobile/cmd/gobind  0.791s

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

Not sure if that helps but when i readd this line: Env: append(os.Environ(), "CGO_ENABLED=0"),
to cmd/gobind/main.go everything works again.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

https://github.com/golang/tools/blob/b29f5f60c37a1dd56e6942c2717b85b976e4a592/go/packages/golist.go#L889-L891

I guess this condition is suspicious: the error message might not be exactly 2 lines. Probably the stderr of gobind -lang go,java,objc golang.org/x/mobile/bind/testdata/cgopkg > /dev/null GOOS=android go list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags -- golang.org/x/mobile/bind/testdata/cgopkg > /dev/null has 4 lines in your environment.

Not sure if that helps but when i readd this line: Env: append(os.Environ(), "CGO_ENABLED=0"),
to cmd/gobind/main.go everything works again.

Thanks! Though this suppresses the error, I don't think this is a correct fix since go/packages would miss some files for Cgo.

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

Hm, I don't see any error if I run go list directly in the terminal:

 rkaufmann  rkaufmann  ~  %  GOPACKAGESDRIVER=off GO111MODULE=off GOOS=android go list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags -- golang.org/x/mobile/bind/testdata/cgopkg > /dev/null
 rkaufmann  rkaufmann  ~  % 

GOPACKAGESDRIVER=off GO111MODULE=off go test -v -run=TestGobind/Go-Cgopkg -count=1 ./cmd/gobind
=== RUN   TestGobind
=== RUN   TestGobind/Go-Cgopkg
--- FAIL: TestGobind (0.27s)
    --- FAIL: TestGobind/Go-Cgopkg (0.27s)
        gobind_test.go:82: gobind -lang go,java,objc golang.org/x/mobile/bind/testdata/cgopkg failed: exit status 1: 2019/08/28 13:37:31 go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags  -- golang.org/x/mobile/bind/testdata/cgopkg]: exit status 2: # runtime/cgo
            gcc_android.c:6:10: schwerwiegender Fehler: android/log.h: No such file or directory
                6 | #include <android/log.h>
                  |          ^~~~~~~~~~~~~~~
            Kompilierung beendet.

FAIL
FAIL    golang.org/x/mobile/cmd/gobind  0.748s
FAIL
@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

Sry, I had to enable cgo with export CGO_ENABLED=1.

After that go list prints this error:

# runtime/cgo
gcc_android.c:6:10: schwerwiegender Fehler: android/log.h: No such file or directory
    6 | #include <android/log.h>
      |          ^~~~~~~~~~~~~~~
Kompilierung beendet.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor

@hajimehoshi hajimehoshi commented Aug 28, 2019

@HeavyHorst Thank you for confirming! I think that's the cause and we should fix go/packages.

@matloob :

As we discussed here, there are two problems in go/packages:

  1. (#33859 (comment)) If go-list's error message doesn't have exactly 2 lines like above, go/packages cannot ignore the Cgo error message. I'm not sure we could remove this checking of line numbers simply.
  2. (#33859 (comment)) If an external gopackagesdriver is specified, Cgo message can also be ignored, but I don't think this is a critical issue.

What do you think?

@HeavyHorst

This comment has been minimized.

Copy link

@HeavyHorst HeavyHorst commented Aug 28, 2019

Just to confirm:

 rkaufmann  rkaufmann  ~  go  …  golang.org  x  mobile  master  ERROR  %  GOPACKAGESDRIVER=off GO111MODULE=off go test -v -run=TestGobind/Go-Cgopkg -count=1 ./cmd/gobind                                                                                                                                        :(
=== RUN   TestGobind
=== RUN   TestGobind/Go-Cgopkg
--- FAIL: TestGobind (0.28s)
    --- FAIL: TestGobind/Go-Cgopkg (0.28s)
        gobind_test.go:82: gobind -lang go,java,objc golang.org/x/mobile/bind/testdata/cgopkg failed: exit status 1: 2019/08/28 14:09:52 go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags  -- golang.org/x/mobile/bind/testdata/cgopkg]: exit status 2: # runtime/cgo
            gcc_android.c:6:10: schwerwiegender Fehler: android/log.h: No such file or directory
                6 | #include <android/log.h>
                  |          ^~~~~~~~~~~~~~~
            Kompilierung beendet.

FAIL
FAIL    golang.org/x/mobile/cmd/gobind  0.729s
FAIL

I then removed strings.Count(stderr.String(), "\n") == 2 from /home/rkaufmann/go/src/golang.org/x/tools/go/packages and everything seem to work afterwards

 rkaufmann  rkaufmann  ~  go  …  golang.org  x  mobile  master  ERROR  %  GOPACKAGESDRIVER=off GO111MODULE=off go test -v -run=TestGobind/Go-Cgopkg -count=1 ./cmd/gobind                                                                                                                                        :(
=== RUN   TestGobind
=== RUN   TestGobind/Go-Cgopkg
--- PASS: TestGobind (1.68s)
    --- PASS: TestGobind/Go-Cgopkg (1.68s)
PASS
ok      golang.org/x/mobile/cmd/gobind  2.143s
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 29, 2019

Change https://golang.org/cl/191942 mentions this issue: go/packages: ignore Cgo compilation error correctly

@davidsteed

This comment has been minimized.

Copy link

@davidsteed davidsteed commented Nov 28, 2019

I am getting this problem
gcc_android.c:6:10: fatal error: 'android/log.h' file not found
and from the above am not clear what I have to do to fix it
gomobile version +d9e324c Sat Nov 23 05:49:42 2019 +0000 (android); androidSDK=/Users/davidsteed/Library/Android/sdk/platforms/android-28

@stonedreamforest

This comment has been minimized.

Copy link

@stonedreamforest stonedreamforest commented Nov 28, 2019

XXXX-Mac:~ XXXXhi$ go get golang.org/x/mobile/cmd/gobind
go: finding golang.org/x/mobile latest
XXXX-Mac:~ XXXXhi$ go get golang.org/x/mobile/cmd/gomobile
go: finding golang.org/x/mobile latest
XXXX-Mac:~ XXXXhi$ gomobile init
gomobile: /usr/local/go/bin/go install golang.org/x/mobile/cmd/gobind failed: exit status 1
go/src/golang.org/x/mobile/internal/importers/ast.go:37:2: cannot find package "golang.org/x/tools/go/packages" in any of:
	/usr/local/go/src/golang.org/x/tools/go/packages (from $GOROOT)
	/Users/XXXXhi/go/src/golang.org/x/tools/go/packages (from $GOPATH)
 go get golang.org/x/mobile/cmd/tools
go: finding golang.org/x/mobile latest
go get golang.org/x/mobile/cmd/tools: module golang.org/x/mobile@upgrade found (v0.0.0-20191123054942-d9e324ca8c38), but does not contain package golang.org/x/mobile/cmd/tools

@WhoJave

This comment has been minimized.

Copy link

@WhoJave WhoJave commented Nov 29, 2019

@stonedreamforest try this

go get -u golang.org/x/tools/...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.