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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hajimehoshi
Copy link
Member

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 16, 2016
@quentinmit quentinmit added this to the Unreleased milestone Nov 16, 2016
@hajimehoshi
Copy link
Member Author

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

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

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

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

hajimehoshi commented Feb 7, 2017

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

@eliasnaur
Copy link
Contributor

eliasnaur commented Feb 7, 2017 via email

@microo8
Copy link

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

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

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Apr 19, 2018
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
Before this CL, unexported fields were ignored for the purposes of
determining which classes a Go struct should extend or implement.
However, the field types were also ignored, resulting in the types
not being generated at all. This CL adds the types of unexported
fields to the set of types to be generated.

Fixes golang/go#17945

Change-Id: I5c6c44b7cdfe0c3d4c4dc44863ae201dca7ae9a4
Reviewed-on: https://go-review.googlesource.com/38635
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
Before this CL, unexported fields were ignored for the purposes of
determining which classes a Go struct should extend or implement.
However, the field types were also ignored, resulting in the types
not being generated at all. This CL adds the types of unexported
fields to the set of types to be generated.

Fixes golang/go#17945

Change-Id: I5c6c44b7cdfe0c3d4c4dc44863ae201dca7ae9a4
Reviewed-on: https://go-review.googlesource.com/38635
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

5 participants