go: x/mobile: gomobile bind is failing with latest version [+cafc553] of gomobile

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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 35 (14 by maintainers)

Most upvoted comments

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

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

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. 🤔

Could you try gomobile with GO111MODULE=off?