我成功地从/system/libs/my_lib.so
目录加载了一个库。如何使用该库中定义的 C/C++ 函数?
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
并存stringFromCpp
在于编译成的文件.c
中.cpp
test_lib.so