Attempt to call JNI_CreateJavaVM from libart.so fails

the first modification here would be to add the diagnosis option Xcheck:jni. This will provide details in case of errors. Add another option by modifying JavaVMOption opt[1]; to JavaVMOption opt[2]; and then, add the following option: opt[1].optionString = "-Xcheck:jni".

Also, the dll must be loaded from it's original location (as other DLLs are involved) and not from your project directory. Mor details are provided in the following post: JNI_CreateJavaVM() terminates with exit code 1

Finally, you should cast the pointer to native interface JNIEnv by modifying:

signed int result = JNI_CreateJavaVM(&(m_jvm), &(m_env), &args);

to

signed int result = JNI_CreateJavaVM(&(m_jvm), (void**)&(m_env), &args);

This should solve the problem.

Oo.oO

It looks like issue is related to library that provides JNI_CreateJavaVM. I am referring to this line

void *libart_dso = dlopen("libart.so", RTLD_NOW); 

If I strip your code from all the stuff that is not related to JVM, and if I use macOS based JDK it works just fine.

--- 8< CUT HERE 8< ----
#include <jni.h>
#include <dlfcn.h>
#include <iostream>
#include "MyJniClass.h"

using namespace std;

bool MyJniClass::init_jvm()
{
    JavaVM *jvm;
    JNIEnv *env = NULL;
    JavaVMOption opt[1];
    opt[0].optionString = "-Djava.class.path=.";

    JavaVMInitArgs args;
    args.version = JNI_VERSION_1_6;
    args.options = opt;
    args.nOptions = 1;
    args.ignoreUnrecognized = JNI_FALSE;

    int status = JNI_CreateJavaVM (&jvm, (void **) &env, &args);

    cout << status << endl;

    return true;
}

int main(int argc, char **argv) {
  MyJniClass jni;
  jni.init_jvm();
}
--- 8< CUT HERE 8< ----
--- 8< CUT HERE 8< ----
#pragma once
class MyJniClass
{
    //Create this once and cache it.
    JavaVM *m_jvm;                      // Pointer to the JVM (Java Virtual Machine)
    JNIEnv *m_env;                      // Pointer to native interface
    public: bool init_jvm();
};
--- 8< CUT HERE 8< ----

and then, I compile the code:

g++ -o lib/recipeNo027_main c/recipeNo027_main.c \
        -I/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/include \
        -I/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/include/darwin/ \
    -rpath -L/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/lib/server -ljvm

(it is based on recipeNo027 from here: http://jnicookbook.owsiak.org/recipe-no-027/)

I can run it without any issues

> lib/recipeNo027_main
0

It looks like something fishy is going on inside your JNI_CreateJavaVM implementation.