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 golang.org/x/mobile/example/reverse/reverse` fails on macOS #17945

Closed
hajimehoshi opened this issue Nov 16, 2016 · 9 comments

Comments

Projects
None yet
5 participants
@hajimehoshi
Copy link
Contributor

commented Nov 16, 2016

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

@hajimehoshi hajimehoshi changed the title `gomobile bind golang.org/x/mobile/example/reverse/reverse` fails on macOS x/mobile: `gomobile bind golang.org/x/mobile/example/reverse/reverse` fails on macOS Nov 16, 2016

@quentinmit quentinmit added this to the Unreleased milestone Nov 16, 2016

@hajimehoshi

This comment has been minimized.

Copy link
Contributor Author

commented Jan 25, 2017

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?

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Feb 7, 2017

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.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor Author

commented Feb 7, 2017

Thank you. I've succeeded gradle on macOS.

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

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Feb 7, 2017

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.

@hajimehoshi

This comment has been minimized.

Copy link
Contributor Author

commented Feb 7, 2017

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

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Feb 7, 2017

@microo8

This comment has been minimized.

Copy link

commented Mar 10, 2017

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
@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Mar 25, 2017

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

@gopherbot

This comment has been minimized.

Copy link

commented Mar 25, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.