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: make RunOnJVM available #26815

Closed
hajimehoshi opened this issue Aug 5, 2018 · 7 comments
Closed

x/mobile: make RunOnJVM available #26815

hajimehoshi opened this issue Aug 5, 2018 · 7 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@hajimehoshi
Copy link
Member

Before golang/mobile@56e3592, 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

@gopherbot gopherbot added this to the Unreleased milestone Aug 5, 2018
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Aug 5, 2018
@eliasnaur
Copy link
Contributor

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.

@hajimehoshi
Copy link
Member Author

hajimehoshi commented Aug 5, 2018

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.

@gopherbot
Copy link
Contributor

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

@eliasnaur
Copy link
Contributor

Is CL 127758 enough to solve your issue?

@hajimehoshi
Copy link
Member Author

Yes, this would solve our problems perfectly!

@ALTree ALTree changed the title x/mobile: proposal: make RunOnJVM available x/mobile: make RunOnJVM available Aug 5, 2018
@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 5, 2018
@ntop001
Copy link

ntop001 commented Aug 11, 2018

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

@xfxdev
Copy link

xfxdev commented Mar 25, 2019

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

@golang golang locked and limited conversation to collaborators Mar 24, 2020
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
CL 122897 changed the visibility of the global JavaVM, JNIEnv and
android.context.Context variables to be internal to gomobile.
However, users of gomobile build programs used those internal
variables to access Java API through Cgo and JNI without Java code.

Make an exported version of mobileinit.RunOnJVM available. This is
quite possibly not the right API for this, but I don't have the
bandwidth to design a better solution. On the other hand, without
access to Java APIs, gomobile build programs are unfairly forced to
add Java code where before there were no need.

Fixes golang/go#26815

Change-Id: I655fb858ffff03a0d542aa9bf97eefc7a22dd5d0
Reviewed-on: https://go-review.googlesource.com/127758
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
CL 122897 changed the visibility of the global JavaVM, JNIEnv and
android.context.Context variables to be internal to gomobile.
However, users of gomobile build programs used those internal
variables to access Java API through Cgo and JNI without Java code.

Make an exported version of mobileinit.RunOnJVM available. This is
quite possibly not the right API for this, but I don't have the
bandwidth to design a better solution. On the other hand, without
access to Java APIs, gomobile build programs are unfairly forced to
add Java code where before there were no need.

Fixes golang/go#26815

Change-Id: I655fb858ffff03a0d542aa9bf97eefc7a22dd5d0
Reviewed-on: https://go-review.googlesource.com/127758
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
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 NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants