Android NDK:不满意 Link 错误

Android NDK: Unsatisfied Link Error

这可能是一个愚蠢的问题,但我正在努力解决这个问题。我在 SO 上看到了一些关于它的 post 但我仍然无法解决错误。

我正面临着名的未确认 link 错误。

我的代码如下

native.cxx:

extern "C" {
    JNIEXPORT jlong JNICALL Java_com_example_VTKNative_JavaVTKLib_init(JNIEnv * env, jobject obj,  jint width, jint height);
    JNIEXPORT void JNICALL Java_com_example_VTKNative_JavaVTKLib_render(JNIEnv * env, jobject obj, jlong renWinP);
    JNIEXPORT void JNICALL Java_com_example_VTKNative_JavaVTKLib_onKeyEvent(JNIEnv * env, jobject obj, jlong udp,
      jboolean down, jint keyCode, jint metaState, jint repeatCount
      );
    JNIEXPORT void JNICALL Java_com_example_VTKNative_JavaVTKLib_onMotionEvent(JNIEnv * env, jobject obj, jlong udp,
      jint action,
      jint eventPointer,
      jint numPtrs,
      jfloatArray xPos, jfloatArray yPos,
      jintArray ids, jint metaState);
};


struct userData
{
  vtkRenderWindow *RenderWindow;
  vtkRenderer *Renderer;
  vtkAndroidRenderWindowInteractor *Interactor;
};

/*
 * Here is where you would setup your pipeline and other normal VTK logic
 */
JNIEXPORT jlong JNICALL Java_com_example_VTKNativeJavaVTKLib_init(JNIEnv * env, jobject obj,  jint width, jint height)
{
    ....
}

我得到的错误是:

06-30 00:02:50.468: E/AndroidRuntime(14916): FATAL EXCEPTION: GLThread 960
06-30 00:02:50.468: E/AndroidRuntime(14916): Process: com.example.vtknative, PID: 14916
06-30 00:02:50.468: E/AndroidRuntime(14916): java.lang.UnsatisfiedLinkError: Native method not found: com.example.vtknative.JavaVTKLib.init:(II)J
06-30 00:02:50.468: E/AndroidRuntime(14916): at com.example.vtknative.JavaVTKLib.init(Native Method)

希望这不是我刚刚错过的疯狂简单的东西。

提前致谢。

您应该将 C++ 函数 Java_com_example_VTKNativeJavaVTKLib_init 重命名为 Java_com_example_vtknative_JavaVTKLib_init 以便它与您的 Java 声明 (com.example.vtknative.JavaVTKLib.init).

相匹配