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 error: cannot find symbol #23327

Closed
laibulle opened this issue Jan 3, 2018 · 8 comments

Comments

Projects
None yet
3 participants
@laibulle
Copy link

commented Jan 3, 2018

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

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/laibulle/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wp/dmlz932d4ms3kwtkrgp0q7vc0000gn/T/go-build306237984=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I am trying build a mobile library for android with gomobile.

What did you expect to see?

A .aar generated archive

What did you see instead?

gomobile bind -target=android haum.io/hink/brain
gomobile: javac -d /var/folders/wp/dmlz932d4ms3kwtkrgp0q7vc0000gn/T/gomobile-work-282095437/javac-output -source 1.7 -target 1.7 -bootclasspath /Users/laibulle/Library/Android/sdk/platforms/android-27/android.jar brain/Brain.java brain/Module.java go/LoadJNI.java go/Seq.java go/Universe.java go/error.java failed: exit status 1
brain/Brain.java:13: error: cannot find symbol
    static { Brain.touch(); }
                  ^
  symbol:   method touch()
  location: class Brain
1 error

make: *** [bind_android] Error 1

@bradfitz bradfitz changed the title Gomobile error: cannot find symbol x/mobile: Gomobile error: cannot find symbol Jan 4, 2018

@gopherbot gopherbot added this to the Unreleased milestone Jan 4, 2018

@gopherbot gopherbot added the mobile label Jan 4, 2018

@mdcnz

This comment has been minimized.

Copy link

commented Jan 4, 2018

Is the underlying Go implementation of the touch() function exported (ie, first letter is capital)?

@laibulle

This comment has been minimized.

Copy link
Author

commented Jan 4, 2018

No, I don't have any Touch function in my code.

@mdcnz

This comment has been minimized.

Copy link

commented Jan 4, 2018

What is "haum.io/hink/brain"? Can you please publish a minimal example of code to reproduce the error?

@laibulle

This comment has been minimized.

Copy link
Author

commented Jan 5, 2018

It is a Home Automation client that I am trying to run on Android Things or Windows 10 Iot core.
I opened the repo https://gitlab.com/haumio/hink here.

You can checkout the init branch and do a make bind_android_brain

@mdcnz

This comment has been minimized.

Copy link

commented Jan 13, 2018

Looks like the error happens when the struct name is the same as the package name; "brain.Brain" in this case. @laibulle can you please try binding after renaming your "Brain" struct?

gomobile seems to want to generate it's own java class with the same name as the package. This generated package class has the touch() function. See gomobile

~ $ mkdir -p $GOPATH/src/haum.io/hink
~ $ cd $GOPATH/src/haum.io/hink/
~/gome/src/haum.io/hink $ git clone --depth 1 https://gitlab.com/haumio/hink .

...go get imports...

~/gome/src/haum.io/hink (init) $ gomobile bind -target=android haum.io/hink/brain
gomobile: javac -d /tmp/gomobile-work-225497599/javac-output -source 1.7 -target 1.7 -bootclasspath /home/mark/Android/Sdk/platforms/android-23/android.jar brain/Brain.java brain/Module.java go/LoadJNI.java go/Seq.java go/Universe.java go/error.java failed: exit status 1
brain/Brain.java:23: error: cannot find symbol
    static { Brain.touch(); }
                  ^
  symbol:   method touch()
  location: class Brain
1 error


~/gome/src/haum.io/hink (init) $ find . -name *go | xargs sed -i s/Brain/Pain/g

~/gome/src/haum.io/hink (init *) $ gomobile bind -target=android haum.io/hink/brain
~/gome/src/haum.io/hink (init *) $ 

go version devel +9745eed4fd Fri Jan 12 05:25:55 2018 +0000 linux/amd64
@laibulle

This comment has been minimized.

Copy link
Author

commented Jan 13, 2018

It works.

Thanks a lot!

@laibulle laibulle closed this Jan 13, 2018

@mdcnz

This comment has been minimized.

Copy link

commented Jan 13, 2018

@eliasnaur @hyangah perhaps this could be fixed in gomobile?

To reproduce:

$GOPATH/test/test.go:

package test

type Test struct{}


$ gomobile bind test
gomobile: javac -d /tmp/gomobile-work-425948145/javac-output -source 1.7 -target 1.7 -bootclasspath /home/mark/Android/Sdk/platforms/android-23/android.jar go/LoadJNI.java go/Seq.java go/Universe.java go/error.java test/Test.java failed: exit status 1
test/Test.java:10: error: cannot find symbol
    static { Test.touch(); }
                 ^
  symbol:   method touch()
  location: class Test
1 error
@gopherbot

This comment has been minimized.

Copy link

commented Jan 13, 2018

Change https://golang.org/cl/87656 mentions this issue: bind: support types with the same title name as their packages

gopherbot pushed a commit to golang/mobile that referenced this issue Jan 17, 2018

Elias Naur
bind: support types with the same title name as their packages
If a Go struct or interface has the same name as its package class,
append an underscore to the generated Java class name.

Fixes golang/go#23327.

Change-Id: Ib680af35c956801073a0effb510a3ed9bbb8b9d1
Reviewed-on: https://go-review.googlesource.com/87656
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>

@golang golang locked and limited conversation to collaborators Jan 13, 2019

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.