我是 jni 的新手,我正在阅读一个教程来实现一个简单的本机方法,但我得到了一个 unsatisfiedlinkerror。据我所知,我完全按照教程中的步骤进行操作。请帮我。
这是java包装器代码:
package com.cookbook.jni;
public class SquaredWrapper {
// Declare native method (and make it public to expose it directly)
public static native int squared(int base);
// Provide additional functionality, that "extends" the native method
public static int to4(int base)
{
int sq = squared(base);
return squared(sq);
}
// Load library
static {
System.loadLibrary("squared");
}
}
这是我的 Android.mk 文件的样子:
LOCAL_PATH := $(调用我的目录)
包括 $(CLEAR_VARS)
LOCAL_MODULE := squared LOCAL_SRC_FILES := squared.c
包括 $(BUILD_SHARED_LIBRARY)
这是我的 .c 文件的样子:
#include "squared.h"
#include <jni.h>
JNIEXPORT jint JNICALL Java_org_edwards_1research_demo_jni_SquaredWrapper_squared
(JNIEnv * je, jclass jc, jint base)
{
return (base*base);
}
这是我的 .h 文件的样子:
enter code here/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_cookbook_jni_SquaredWrapper */
#ifndef _Included_com_cookbook_jni_SquaredWrapper
#define _Included_com_cookbook_jni_SquaredWrapper
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_cookbook_jni_SquaredWrapper
* Method: squared
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_com_cookbook_jni_SquaredWrapper_squared
(JNIEnv *, jclass, jint);
#ifdef __cplusplus
}
#endif
#endif