Go: x/mobile: make RunOnJVM available

Created on 5 Aug 2018  路  7Comments  路  Source: golang/go

Before https://github.com/golang/mobile/commit/56e3592fa7a0582e84d783579d2eb8e6114e0312, I was able to use an exported variable current_vm and current_ctx and call JNI functions. However, as these variables are no longer exported, it is impossible to access JNI functions. I admit accessing current_vm was not a good manner, but we rely on JNI functions heavily so we'd be really glad if RunOnJVM could be available (again?).

For iOS, Objective-C functions are available via cgo, so there is no problem.

CC @eliasnaur

FrozenDueToAge NeedsDecision mobile

Most helpful comment

Is CL 127758 enough to solve your issue?

All 7 comments

What is your use case? If you have any kind of Java code in your app, you can call into C through JNI and attain a JNIEnv pointer (and through that, a JavaVM pointer) that way.

https://github.com/hajimehoshi/ebiten/blob/master/internal/devicescale/impl_android.go Actual usecase to call getResources().getDisplayMetrics().density in Java.

To call JNI functions, JavaVM*, JNIEnv*, and context values are required, but how can I get them via Cgo? That library doesn't have any Java code so that I can use the lib with gomobile build.

Change https://golang.org/cl/127758 mentions this issue: app: add RunOnJVM to allow Cgo access to the Android JVM and context

Is CL 127758 enough to solve your issue?

Yes, this would solve our problems perfectly!

@eliasnaur Great! I'm porting a game to Android, too. JNI interface is heavily used in my App. With RunOnJVM we can implement most of the Android functions.

@eliasnaur this is only available for app, not for gobind libraries:(

Was this page helpful?
0 / 5 - 0 ratings