真的需要帮助.我被困在这里.谢谢你的任何建议.
我正在使用NDK构建一个so库,然后在java中调用它.但我只能在主要活动中将其称为启动活动,如果我尝试在主活动启动的另一个活动中调用它,它将失败.我在每个活动的OnCreate方法中调用该方法,代码非常简单如下:
System.loadLibrary("svm-predict");
double dd = predictbattery("fsdfsdf", "sdfsdf", 0);
错误的堆栈是:
12-08 00:47:08.153: E/AndroidRuntime(13370): FATAL EXCEPTION: main
12-08 00:47:08.153: E/AndroidRuntime(13370): java.lang.UnsatisfiedLinkError: predictbattery
12-08 00:47:08.153: E/AndroidRuntime(13370): at com.dash.RunningLogActivity.predictbattery(Native Method)
12-08 00:47:08.153: E/AndroidRuntime(13370): at com.dash.RunningLogActivity.onCreate(RunningLogActivity.java:58)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.os.Handler.dispatchMessage(Handler.java:99)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.os.Looper.loop(Looper.java:123)
12-08 00:47:08.153: E/AndroidRuntime(13370): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-08 00:47:08.153: E/AndroidRuntime(13370): at java.lang.reflect.Method.invokeNative(Native Method)
12-08 00:47:08.153: E/AndroidRuntime(13370): at java.lang.reflect.Method.invoke(Method.java:507)
12-08 00:47:08.153: E/AndroidRuntime(13370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-08 00:47:08.153: E/AndroidRuntime(13370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-08 00:47:08.153: E/AndroidRuntime(13370): at dalvik.system.NativeStart.main(Native Method)
最佳答案 JNI C文件中的方法签名也包含包名和类名.所以你不能从不同的活动/类中调用相同的函数.
例如.
JNIEXPORT float JNICALL
Java_com_artifex_mupdf_MuPDFCore_getPageWidth(JNIEnv *env, jobject thiz)
{ }
这个JNI方法’getPageWidth()’只能从中调用
com.artifex.mupdf.MuPDFCore
类.因此,您只能从主要活动中调用它.