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/bind: cannot make JNI calls to Go function names with underscore #18536

Closed
imreotto opened this issue Jan 6, 2017 · 1 comment
Closed
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@imreotto
Copy link

imreotto commented Jan 6, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.1 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/storage/data/gocode:/storage/data/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build712135149=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

In go Create a method with underscore in the name
func Exported_func() {}
$ gomobile bind -target=android .../goexport
results:

Archive:  goexport.aar
  Length      Date    Time    Name
---------  ---------- -----   ----
      147  1980-00-00 00:00   AndroidManifest.xml
       25  1980-00-00 00:00   proguard.txt
     8636  1980-00-00 00:00   classes.jar
  2481408  1980-00-00 00:00   jni/arm64-v8a/libgojni.so
  1919436  1980-00-00 00:00   jni/x86/libgojni.so
  2402712  1980-00-00 00:00   jni/x86_64/libgojni.so
  1990960  1980-00-00 00:00   jni/armeabi-v7a/libgojni.so
        0  1980-00-00 00:00   R.txt
        0  1980-00-00 00:00   res/
---------                     -------
  8803324                     9 files

so far so good
$nm -D jni/x86_64/libgojni.so
....
Java_go_goexport_Goexport_exported_func
...

What did you expect to see?

From android to call function Goexport.exported_func(); withouth error

What did you see instead?

java.lang.UnsatisfiedLinkError: No implementation found for void go.goexport.Goexport.exported_func() (tried Java_go_goexport_Goexport_exported_1func and Java_go_goexport_Goexport_exported_1func__)


According to this: resolving_native_method_names

Names generated in jni which has _ in name should be replaced with _1 as seen above (tried ..)

@rakyll rakyll changed the title x/mobile: x/mobile/bind: cannot make JNI calls to Go function names with underscore Jan 6, 2017
@rakyll rakyll added this to the Unreleased milestone Jan 6, 2017
@bradfitz bradfitz added the mobile Android, iOS, and x/mobile label Jul 20, 2017
@gopherbot
Copy link

Change https://golang.org/cl/101156 mentions this issue: bind: support underscores in identifiers

@golang golang locked and limited conversation to collaborators Mar 21, 2019
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
Fixes golang/go#18536

Change-Id: I82c5993547e4d1d0df14726ccc569e1f57128072
Reviewed-on: https://go-review.googlesource.com/101156
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
Fixes golang/go#18536

Change-Id: I82c5993547e4d1d0df14726ccc569e1f57128072
Reviewed-on: https://go-review.googlesource.com/101156
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 mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

4 participants