Go: x/mobile: `gomobile bind golang.org/x/mobile/example/reverse/reverse` fails on macOS

Created on 16 Nov 2016  Â·  9Comments  Â·  Source: golang/go

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

go version go1.7 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7t/qw3np69559591s1v0mk5_p1m0000gn/T/go-build948107820=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

$ gomobile bind golang.org/x/mobile/example/reverse/reverse
gomobile: loadExportData failed go install -pkgdir=/Users/hajimehoshi/go/pkg/gomobile/pkg_android_arm -tags="" -gcflags=-shared -ldflags=-shared golang.org/x/mobile/example/reverse/reverse failed: exit status 1
../../../golang.org/x/mobile/example/reverse/reverse/reverse.go:9:2: cannot find package "Java/android/databinding/DataBindingUtil" in any of:
        /usr/local/go/src/Java/android/databinding/DataBindingUtil (from $GOROOT)
        /var/folders/7t/qw3np69559591s1v0mk5_p1m0000gn/T/gomobile-work-600308528/gen/src/Java/android/databinding/DataBindingUtil (from $GOPATH)
        /Users/hajimehoshi/go/src/Java/android/databinding/DataBindingUtil
../../../golang.org/x/mobile/example/reverse/reverse/reverse.go:11:2: cannot find package "Java/android/support/v7/app" in any of:
        /usr/local/go/src/Java/android/support/v7/app (from $GOROOT)
        /var/folders/7t/qw3np69559591s1v0mk5_p1m0000gn/T/gomobile-work-600308528/gen/src/Java/android/support/v7/app (from $GOPATH)
        /Users/hajimehoshi/go/src/Java/android/support/v7/app
../../../golang.org/x/mobile/example/reverse/reverse/reverse.go:12:2: cannot find package "Java/go/reverse/R/layout" in any of:
        /usr/local/go/src/Java/go/reverse/R/layout (from $GOROOT)
        /var/folders/7t/qw3np69559591s1v0mk5_p1m0000gn/T/gomobile-work-600308528/gen/src/Java/go/reverse/R/layout (from $GOPATH)
        /Users/hajimehoshi/go/src/Java/go/reverse/R/layout
../../../golang.org/x/mobile/example/reverse/reverse/reverse.go:13:2: cannot find package "Java/go/reverse/databinding/ActivityMainBinding" in any of:
        /usr/local/go/src/Java/go/reverse/databinding/ActivityMainBinding (from $GOROOT)
        /var/folders/7t/qw3np69559591s1v0mk5_p1m0000gn/T/gomobile-work-600308528/gen/src/Java/go/reverse/databinding/ActivityMainBinding (from $GOPATH)
        /Users/hajimehoshi/go/src/Java/go/reverse/databinding/ActivityMainBinding

$ gomobile version
gomobile version +b8794a2 Thu Nov 3 14:40:43 2016 +0000 (android,ios); androidSDK=/Users/hajimehoshi/Library/Android/sdk/platforms/android-24

What did you expect to see?

Successfully build.

What did you see instead?

Build error (packages beginning with Java are not found).

FrozenDueToAge NeedsInvestigation

Most helpful comment

I've mailed https://go-review.googlesource.com/38635 that should fix your case.

All 9 comments

The situation has changed a little: the current error message is

$ gomobile bind golang.org/x/mobile/example/reverse/reverse
gomobile: failed to find Java class android.support.v7.app.AppCompatActivity, embedded by reverse.MainActivity

Is this expected?

That's expected, you can't directly gomobile bind the reverse package since it depends on Java classes defined by the gradle build. Go to example/reverse/android and run gradlew installDebug from there instead.

Thank you. I've succeeded gradle on macOS.

BTW, can I request a feature to make it enable to gomobile-bind this without gradle?

You can do so already, by replicating what the gobind gradle plugin does. For simple cases, adding -classpath to gomobile will be enough. For the hard cases where Go code references Java code that itself references Go types, the the gobind tool is used to generate the Java classes for exported Go types and functions, breaking the reference cycle.

Thanks, but I still don't understand what path should be specified for classpath.

the gomobile bind takes a -classpath argument that should point to the
class path with (in your case) the support library.

Den tir. 7. feb. 2017 17.28 skrev Hajime Hoshi notifications@github.com:

Thanks, but I still don't understand what path should be specified for
classpath. What did you mean "classpath to gomobile"?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/golang/go/issues/17945#issuecomment-278053309, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAgCDHEQDeOex89hs8wc9Y_Xm3xGCv09ks5raJuqgaJpZM4K0NB3
.

I've managed to build the reverse.go example with gradle successfully, but how is that when I add some java.lang imports to the reverse.go:

import (
    "Java/android/databinding/DataBindingUtil"
    "Java/android/os"
    "Java/android/support/v7/app"
    gopkg "Java/reverse"
    rlayout "Java/reverse/R/layout"
    "Java/reverse/databinding"
    "Java/reverse/databinding/ActivityMainBinding"
    "Java/java/lang/Float"
    "Java/java/lang"
)

then use it somewhere:

type MainActivity struct {
    app.AppCompatActivity
    binding databinding.ActivityMainBinding
    f lang.Float
}

and run ./gradlew assembleDebug then gobind will fail on that it cannot find java.lang packages?

:gomobileDebug
/home/micro/Workspace/bin/gomobile: loadExportData failed go install -pkgdir=/home/micro/Workspace/pkg/gomobile/pkg_android_arm -gcflags=-shared -ldflags=-shared golang.org/x/mobile/example/reverse/reverse failed: exit status 1
../reverse/reverse.go:20:2: cannot find package "Java/java/lang" in any of:
        /usr/lib/go/src/Java/java/lang (from $GOROOT)
        /tmp/gomobile-work-119975885/gen/src/Java/java/lang (from $GOPATH)
        /home/micro/Workspace/src/Java/java/lang
../reverse/reverse.go:19:2: cannot find package "Java/java/lang/Float" in any of:
        /usr/lib/go/src/Java/java/lang/Float (from $GOROOT)
        /tmp/gomobile-work-119975885/gen/src/Java/java/lang/Float (from $GOPATH)
        /home/micro/Workspace/src/Java/java/lang/Float

:gomobileDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gomobileDebug'.
> Process 'command '/home/micro/Workspace/bin/gomobile'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I've mailed https://go-review.googlesource.com/38635 that should fix your case.

CL https://golang.org/cl/38635 mentions this issue.

Was this page helpful?
0 / 5 - 0 ratings