System.load for library loading

android, java-native-interface, load

Solution

I have solved my problem.

It was necessary to write

System.load("/system/lib/libtest_lib.so");

instead of

System.load("/system/lib/test_lib.so");

So strange. If I run

adb shell 
ls /system/lib

I will see test_lib.so file. Why is it correctlly to load library using lib prefix?

Problem

I loaded a library from the `/system/libs/my_lib.so` directory successfully. How can I use the C/C++ functions which are defined in this library? ``` public class MainFrom extends Activity { private static final String LOG_TAG = "MainFrom"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // How to use the functions of test_lib.so? /* java.lang.UnsatisfiedLinkError: stringFromC String s1 = stringFromC(), s2 = stringFromCpp(); Log.w(LOG_TAG, stringFromC()); Log.w(LOG_TAG, stringFromCpp()); */ } public native String stringFromC(); public native String stringFromCpp(); static { try { System.load("/system/lib/test_lib.so"); Log.i(LOG_TAG, "MainFrom. Success!"); } catch (UnsatisfiedLinkError e) { Log.e(LOG_TAG, "MainFrom. UnsatisfiedLinkError"); } } } ``` `stringFromC` and `stringFromCpp` exist in `.c` and `.cpp` files which were compiled to `test_lib.so`

Original source