How do I access JavaVM from androidNativeArm32 without NativeActivity and from a library?


I originally created this post here:

but I figure this place might be better suited for asking for help rather than reporting an issue.

Onto the question:

Following the example demonstrated in:

I got the main idea on how to call Android API’s from native code, however. I can not rely on NativeActivity being used and need some sort of way to gain access to JavaVM

My current idea is to setup the library with

fun JNI_OnLoad(vm: kotlinx.cinterop.CValuesRef<>?, reserved: kotlinx.cinterop.CValuesRef<*>?): {
    __android_log_write(ANDROID_LOG_INFO.convert(), "KonanActivity", "JNI BOOTED UP!")
    return JNI_VERSION_1_2

fun JNI_OnUnload(vm: kotlinx.cinterop.CValuesRef< >?, reserved: kotlinx.cinterop.CValuesRef<*>?): kotlin.Unit {
    __android_log_write(ANDROID_LOG_INFO.convert(), "KonanActivity", "JNI SHUT DOWN!")

In order to gain access to the JavaVM and then proceed to setting it up like in the repository linked above.

However this will cause issues to the exported *.so file because the types won’t be handled properly. What would be the easiest way to gain access to the JavaVM the library is attached to?