-
Notifications
You must be signed in to change notification settings - Fork 18k
x/mobile/cmd/gomobile: RunOnJVM is not available from init functions #25255
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
Comments
golang/mobile@56e3592 makes it impossible to access |
The above problem was solved #26815 BTW, to use JNI in
|
My understanding is that |
Sorry I missed this issue. Yes that's the way it works at the moment. This change was needed because older versions of gomobile used reflection that was blacklisted by Android. Do you really have to use init() functions? Can't you use your own initX() functions? You don't have to bind to an activity, you can also do it from a Service or even from the Application. But I guess that doesn't solve your problem. |
Hi,
I might not, but other people might. I'm developing a library working with gomobile. If a function uses RunOnJVM, the function can be called from main and after but not from init, and this is not a good user experience. |
In my library, JNI functions are called from Go side. JVM is accessed via a global C variable
current_vm
. I admit depending this variable is not a good way, but there is no other way to access JNI from Go. Actual code is https://github.com/hajimehoshi/ebiten/blob/master/internal/jni/jni_android.goI realized that
current_vm
is not initialized yet wheninit
functions are called. IIUC,current_vm
is initialized atSetCurrentContext
when the activity'sonCreate
is called, and thisonCreate
is called after allinit
functions are called and beforemain
is called.Wouldn't it be possible to make JVM available even from
init
functions? For gomobile-bind, asinit
functions are automatically called before callingSetCurrentContext
, then it might be impossible. If this is impossible, is there other way to call JNI functions from Go side?As for iOS, Objective-C binding via cgo is available and there is not such problem.
The text was updated successfully, but these errors were encountered: