0

Now I load my C++ code by:

final DynamicLibrary nativeAddLib =
  Platform.isAndroid
    ? DynamicLibrary.open("libnative_add.so")
    : DynamicLibrary.process();

but the JNI_OnLoad in my .cpp file is not executed:

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
  LOGI("JNI_OnLoad!");
}
LvSheng
  • 33
  • 6
  • Automatic execution of `JNI_OnLoad` only happens when a JVM is instructed to load the DLL. It seems you are loading the DLL from Dart. – Botje Jan 13 '20 at 10:06
  • `It seems you are loading the DLL from Dart` yes, it's true – LvSheng Jan 14 '20 at 06:03

1 Answers1

0

As @Botje said, it seems that the DynamicLibrary.open does not instruct JVM to load the library.

Finally I add an extra .so library to encapsulate the interaction with JNI, and load it via System.loadLibrary in java.

LvSheng
  • 33
  • 6