问题
My native method cannot be found and I cannot solve it.
java code:
package org.cocos2dx.cppemptytest;
public class TestJNI {
static {
System.loadLibrary("cpp_empty_test");
}
public native String moveto();
}
native code:
#include "AppDelegate.h"
#include "platform/android/jni/JniHelper.h"
#include <jni.h>
#include <android/log.h>
#include <stdlib.h>
#include "cocos2d.h"
#define LOG_TAG "main"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
using namespace cocos2d;
AppDelegate *pAppDelegate;
void cocos_android_app_init (JNIEnv* env, jobject thiz) {
LOGD("cocos_android_app_init");
pAppDelegate = new AppDelegate();
}
extern "C" {
JNIEXPORT jstring JNICALL Java_org_cocos2dx_cppemptytest_TestJNI_moveto
( JNIEnv* env, jobject thiz){
return env->NewStringUTF("default");
}
}
in Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cpp_empty_test
LOCAL_MODULE_FILENAME := libcpp_empty_test
LOCAL_SRC_FILES := main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_LDLIBS := -llog
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../../../../extensions \
$(LOCAL_PATH)/../../../.. \
$(LOCAL_PATH)/../../../../cocos/editor-support
LOCAL_STATIC_LIBRARIES := cocos2dx_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
Output gives unsatisfied link error, but my naming is correct I guess. Are there any other reasons why this error occurrs?
E/AndroidRuntime(30310): java.lang.UnsatisfiedLinkError:
Native method not found:
org.cocos2dx.cppemptytest.TestJNI.moveto:()Ljava/lang/String;
回答1:
Try to change your in Android.mk to this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libcpp_empty_test
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
来源:https://stackoverflow.com/questions/28603269/unsatisfiedlinkerror-native-method-not-found-but-correct-naming