I have an Android project that contains a class that uses JNI to pull a value from a C function. The C function was built into a library using NDK. The value returned from the C function is in turn used to initialize a variable inside a class when its first loaded. This works fine. However, I also want it to work when the library is missing by providing a default value. So Im using something like this:
static native String getstring();
static {
try {
System.loadLibrary("library");
NAME = getstring();
}
catch (Exception e) {
NAME = "Default";
}
}
Despite the catch, Im still getting a UnsatisfiedLinkError when I try to run this code with the library missing. Why am I not catching the exception? What am I doing wrong?
The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.
Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++.
jni/libs folder is where your shared library files are built from the C/C++ sources. Your native code gets compiled and depending on the value you had set in your application.mk file for the parameter APP_ABI: = <all | x86 | armv7a | armeabi-v7 | mips>
Android provides Native Development Kit (NDK) to support native development in C/C++, besides the Android Software Development Kit (Android SDK) which supports Java. [TODO] more.
UnsatisfiedLinkError
is not a subclass of Exception
. The hierarchy of UnsatisfiedLinkError
is:
Throwable->Error->UnsatisfiedLinkError
You better catch UnsatisfiedLinkError
if you want to handle it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With