java.lang.UnsatisfiedlinkError : Native method not found

标签 java android android-ndk java-native-interface

我正在尝试使用 jni 构建一个演示应用程序(我是新手)。我已经用谷歌搜索了这个问题,但没有任何帮助。

下面是我正在使用的代码:

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 <jni.h>
  /* 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

最佳答案

您没有实现这些功能。请注意您的第一行(如下),该行末尾有一个分号。然后,您创建具有不同格式的第二个函数 int soma(int,int)

...Java_com_example_example_Operacoes_soma (JNIEnv *, jclass, jint, jint);<<<wrong

您需要使用与声明完全相同的格式来实现 native 函数。

JNIEXPORT jint JNICALL Java_com_example_example_Operacoes_soma (JNIEnv * env, jclass clazz, jint a, jint b)
{
     return a + b;
}

关于java.lang.UnsatisfiedlinkError : Native method not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21935913/

相关文章:

java - 在同一 JVM 中检测到多个正在运行的 SparkContext - Java Spark

android-ndk - Android 的 LinPhone 构建过程

java - 在 ImageIO 插件中根据 EXIF 方向实现 JPEG 图片的自动旋转

java - Android BroadcastReceiver 不更新小部件

android - 如何更改ListView中多个项目行删除的背景颜色

android - 在您的程序中使用人脸检测

Android AppCompat 库使用

android - ACTION_IMAGE_CAPTURE Intent : Avoid Activity being destroyed/process being killed

安卓工作室 NDK 等级 : Cannot find share library

java - 需要帮助将 Java 代码更改为方法 addText (String text)