java.lang.UnsatisfiedLinkError中:本机方法未找到 [英] java.lang.UnsatisfiedLinkError: Native method not found
问题描述
我试图做一个NDK的应用程序,但我得到这个错误 java.lang.UnsatisfiedLinkError中:本机方法未找到:com.example.hellondk.jni.HelloNDK.hello :()我
我不明白,因为C ++函数的名称是相同的Java包名称和类
HelloNDK.cpp
的#include< jni.h>
JNIEXPORT jint JNICALL Java_com_example_hellondk_jni_HelloNDK_hello(JNIEnv的* ENV,jobject O){
返程(jint)2;
}
HelloNDK.java
包com.example.hellondk.jni;
公共类HelloNDK {
公共本地INT你好();
静态{
的System.loadLibrary(HelloNDK);
}
}
Android.mk
LOCAL_PATH:= $(叫我-DIR)
包括$(CLEAR_VARS)
LOCAL_MODULE:= HelloNDK
LOCAL_SRC_FILES:= HelloNDK.cpp
包括$(BUILD_SHARED_LIBRARY)
您正在导出为一个C ++函数,但是JNI链接并不了解C ++名字改编,所以它不能够找到它。
您可以使用的externC
有没有出口的C ++名字改编功能:
的externCJNIEXPORT jint JNICALL Java_com_example_hellondk_jni_HelloNDK_hello(JNIEnv的* ENV,jobject O)
{
返程(jint)2;
}
I'm trying to make a NDK application, but I get this error java.lang.UnsatisfiedLinkError: Native method not found: com.example.hellondk.jni.HelloNDK.hello:()I
I don't understand because the name of the C++ function is the same as the Java packagename and class
HelloNDK.cpp
#include <jni.h>
JNIEXPORT jint JNICALL Java_com_example_hellondk_jni_HelloNDK_hello(JNIEnv* env, jobject o){
return (jint) 2;
}
HelloNDK.java
package com.example.hellondk.jni;
public class HelloNDK {
public native int hello();
static {
System.loadLibrary("HelloNDK");
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := HelloNDK
LOCAL_SRC_FILES := HelloNDK.cpp
include $(BUILD_SHARED_LIBRARY)
You're exporting it as a C++ function, but the JNI linker doesn't understand C++ name mangling, so it won't be able to find it.
You can use extern "C"
to have the function exported without C++ name mangling:
extern "C" JNIEXPORT jint JNICALL Java_com_example_hellondk_jni_HelloNDK_hello(JNIEnv* env, jobject o)
{
return (jint) 2;
}
这篇关于java.lang.UnsatisfiedLinkError中:本机方法未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!