Working toward making a vulkan + OpenXR app on Oculus Quest: How can I get a pointer to the JVM?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Working toward making a vulkan + OpenXR app on Oculus Quest: How can I get a pointer to the JVM?

Phil Dougherty
Slowly figuring out how to get all of these things correctly hooked together-

on the oculus website ( https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) it has the following snippet:

loaderInitializeInfoAndroid.applicationVM = data->applicationVM; 

This is part of a process to hook up the openXR loader. However, this documentation shows nothing of how to get such a pointer. Googling "NDK get JVM" isn't coming up with any straightforward documentation either...

So, how can I get access to the JVM from within C++ using the NDK?

What do I need to link against? What do I need to #include? What initialization do I need to do?

I'm using android_native_app_glue.h, which gets me access to the ANativeActivity (via struct android_app), which I also needed in the snippet from the oculus website. But nothing is there regarding the JVM.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e85f2b88-218f-4606-a297-be6b9b42f8a3n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Working toward making a vulkan + OpenXR app on Oculus Quest: How can I get a pointer to the JVM?

mic _

On Wed, Aug 12, 2020 at 4:37 AM Phil Dougherty <[hidden email]> wrote:
Slowly figuring out how to get all of these things correctly hooked together-

on the oculus website ( https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) it has the following snippet:

loaderInitializeInfoAndroid.applicationVM = data->applicationVM; 

This is part of a process to hook up the openXR loader. However, this documentation shows nothing of how to get such a pointer. Googling "NDK get JVM" isn't coming up with any straightforward documentation either...

So, how can I get access to the JVM from within C++ using the NDK?

What do I need to link against? What do I need to #include? What initialization do I need to do?

I'm using android_native_app_glue.h, which gets me access to the ANativeActivity (via struct android_app), which I also needed in the snippet from the oculus website. But nothing is there regarding the JVM.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e85f2b88-218f-4606-a297-be6b9b42f8a3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAJwpw3bH4d4zFG%3DHbB7iBZCOLUPZzqtpVCBCK6auVBidb3nonw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Working toward making a vulkan + OpenXR app on Oculus Quest: How can I get a pointer to the JVM?

Florian Limberger
I don't know how the Oculus SDK integrates with Android, but typically, an Android app has a Java entrypoint to the native code in form of a native method, like this:

public class MyActivity extends Activity {
    static {
        System.loadLibrary("mylib");
    }

    public void onCreate() {
        super.onCreate();
        if (!myInit()) {
            // handle the error
        }
    }

    private static native boolean myInit();
}

This method provided by a shared library (in this example mylib.so) like described here: https://developer.android.com/training/articles/perf-jni#native-libraries
All the native functions take a pointer to a JNIEnv as first parameter, which can then used to retrieve a pointer to the JVM:

#include <jni.h>

// Do the JNI_OnLoad() dance here, described in the link above

jboolean myInit(JNIEnv *env, jclass clazz) {
    (void)clazz;
    JavaVM *jvm = NULL;
    jint result = GetJavaVM(env, &jvm);
    if (result < 0) {
        return JNI_FALSE;
    }
    return JNI_TRUE;
}

JNI Documentation is available here: https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html

Disclaimer: I wrote all code above from top of my head and tested nothing of this. I hope this helps anyway.
mic schrieb am Mittwoch, 12. August 2020 um 09:12:42 UTC+2:

On Wed, Aug 12, 2020 at 4:37 AM Phil Dougherty <[hidden email]> wrote:
Slowly figuring out how to get all of these things correctly hooked together-

on the oculus website ( https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) it has the following snippet:

loaderInitializeInfoAndroid.applicationVM = data->applicationVM; 

This is part of a process to hook up the openXR loader. However, this documentation shows nothing of how to get such a pointer. Googling "NDK get JVM" isn't coming up with any straightforward documentation either...

So, how can I get access to the JVM from within C++ using the NDK?

What do I need to link against? What do I need to #include? What initialization do I need to do?

I'm using android_native_app_glue.h, which gets me access to the ANativeActivity (via struct android_app), which I also needed in the snippet from the oculus website. But nothing is there regarding the JVM.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e85f2b88-218f-4606-a297-be6b9b42f8a3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/31190d79-d0b8-4204-a86f-2f2962316917n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Working toward making a vulkan + OpenXR app on Oculus Quest: How can I get a pointer to the JVM?

Phil Dougherty
In reply to this post by mic _
ah awesome. that's... really strange they would have me separately pass in the ANativeActivity AND the JavaVM when one is accessible from the other...

On Wednesday, August 12, 2020 at 2:12:42 AM UTC-5 mic wrote:

On Wed, Aug 12, 2020 at 4:37 AM Phil Dougherty <[hidden email]> wrote:
Slowly figuring out how to get all of these things correctly hooked together-

on the oculus website ( https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) it has the following snippet:

loaderInitializeInfoAndroid.applicationVM = data->applicationVM; 

This is part of a process to hook up the openXR loader. However, this documentation shows nothing of how to get such a pointer. Googling "NDK get JVM" isn't coming up with any straightforward documentation either...

So, how can I get access to the JVM from within C++ using the NDK?

What do I need to link against? What do I need to #include? What initialization do I need to do?

I'm using android_native_app_glue.h, which gets me access to the ANativeActivity (via struct android_app), which I also needed in the snippet from the oculus website. But nothing is there regarding the JVM.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e85f2b88-218f-4606-a297-be6b9b42f8a3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/0a674d39-5042-4936-8db9-2204a1511caen%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Working toward making a vulkan + OpenXR app on Oculus Quest: How can I get a pointer to the JVM?

Florian Limberger
As far as I understand it, ANativeActivity is for convenience and not necessary.
At work we use native code from a Service with the approach I described above.
If you use ANativeActivity, you do not need to retrieve the pointer to the JVM manually.

[hidden email] schrieb am Mittwoch, 12. August 2020 um 17:58:54 UTC+2:
ah awesome. that's... really strange they would have me separately pass in the ANativeActivity AND the JavaVM when one is accessible from the other...

On Wednesday, August 12, 2020 at 2:12:42 AM UTC-5 mic wrote:

On Wed, Aug 12, 2020 at 4:37 AM Phil Dougherty <[hidden email]> wrote:
Slowly figuring out how to get all of these things correctly hooked together-

on the oculus website ( https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) it has the following snippet:

loaderInitializeInfoAndroid.applicationVM = data->applicationVM; 

This is part of a process to hook up the openXR loader. However, this documentation shows nothing of how to get such a pointer. Googling "NDK get JVM" isn't coming up with any straightforward documentation either...

So, how can I get access to the JVM from within C++ using the NDK?

What do I need to link against? What do I need to #include? What initialization do I need to do?

I'm using android_native_app_glue.h, which gets me access to the ANativeActivity (via struct android_app), which I also needed in the snippet from the oculus website. But nothing is there regarding the JVM.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e85f2b88-218f-4606-a297-be6b9b42f8a3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/2330744c-97d0-4ec6-ba4b-d30deaecf4b5n%40googlegroups.com.