我正在尝试使用jni构建一个演示应用程序(我对它很陌生)。我已经谷歌和关于这个问题,但没有任何帮助。java.lang.UnsatisfieldlinkError:找不到本地方法
下面是我使用的代码:
include $(CLEAR_VARS)
LOCAL_MODULE := example
LOCAL_SRC_FILES := com_example_example_Operacoes.c
include $(BUILD_SHARED_LIBRARY)
Operacoes.java 包com.example.example;
public class Operacoes {
static {
System.loadLibrary("example");
}
//Versao nativa do metodo soma
public static native int soma(int a, int b);
//Versao nativa do metodo subtracao
public static native int sub(int a, int b);
}
com_example_example_Operacoes.h
# include "com_example_example_Operacoes.c"
JNIEXPORT jint JNICALL Java_com_example_example_Operacoes_soma (JNIEnv *, jclass, jint, jint);
int soma(int a, int b){
return a + b;
}
JNIEXPORT jint JNICALL Java_com_example_example_Operacoes_sub (JNIEnv *, jclass, jint, jint);
int sub(int a, int b){
return a - b;
}
com_example_example_Operacoes.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class com_example_example_Operacoes */
#ifndef _Included_com_example_example_Operacoes
#define _Included_com_example_example_Operacoes
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_example_Operacoes
* Method: soma
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_com_example_example_Operacoes_soma (JNIEnv *, jclass, jint, jint);
/*
* Class: com_example_example_Operacoes
* Method: sub
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_com_example_example_Operacoes_sub (JNIEnv *, jclass, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
+0
检查您是否在lib目录下成功生成了.SO文件,如果没有.so文件,它将无法正常运行 –