I have an Android project that contains a class that uses JNI to pull a value from function C. Function C has been built into the library using the NDK. The value returned by the C function, in turn, is used to initialize the variable inside the class when it is first loaded. It works great. However, I also want it to work when the library is missing, providing a default value. Therefore, I use something like this:
static native String getstring(); static { try { System.loadLibrary("library"); NAME = getstring(); } catch (Exception e) { NAME = "Default"; } }
Despite the trick, I still get UnsatisfiedLinkError when I try to run this code with a missing library. Why can't I see an exception? What am I doing wrong?
android linker android-ndk jni
Eno
source share