我剛開始使用NDK,我跑了Hello_Jni,我知道這是如何工作,但我想嘗試做這樣的事情,不能得到它的工作(我做這個手動)傳遞參數給JNI給出錯誤java.lang.UnsatisfiedLinkError
simple.c
#include "simple.h"
#include <jni.h>
JNIEXPORT jdouble JNICALL
Java_com_example_Test_round_decimals (JNIEnv * env, jobject obj, jdouble value, jint decimals) {
double m = pow (10, decimals);
return (double) round (value * m)/m;
}
JNIEXPORT jstring JNICALL Java_com_example_Test_hello(JNIEnv* env, jobject javaThis) {
return (*env)->NewStringUTF(env, "Hello from ME!");
}
simple.h
#include <stdio.h>
#include <stdlib.h>
#include "math.h"
#include <string.h>
#include <jni.h>
JNIEXPORT jdouble JNICALL Java_com_example_Test_round_decimals (JNIEnv * env, jobject obj,jdouble value, jint decimals);
JNIEXPORT jstring JNICALL Java_com_example_Test_hello(JNIEnv* env, jobject javaThis);
活動
public class Test{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
double test = round_decimals(10.1234,2);
double test2 = hello();
Log.i("Round","Number" + test); // i would like to get this
Log.i("String","hello? " + test2); // this works it shows "Hello From ME!"
}
public native double round_decimals(double value, int decimals);
public native String hello();
static {
System.loadLibrary("simple");
}
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := simple
LOCAL_SRC_FILES := simple.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_SHARED_LIBRARY)
android.mk,simple.c和simple.h是在我的活動的JNI文件夾中。 而且還在我的活動文件夾中運行Build-ndk顯示沒有錯誤
但是,當我嘗試在平板電腦上構建它時,出現此錯誤。
java.lang.UnsatisfiedLinkError:round_decimals
包名是什麼? – Michael
java.com.example但是,當我編輯它與簡單的字符串工作 – MePo