System.load to load the library
I downloaded the library from the directory /system/libs/my_lib.so
successfully. How can I use the C / C ++ functions 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 files .c
and .cpp
that were compiled intotest_lib.so
+3
source to share
3 answers