简体   繁体   中英

UnsatisfiedLinkError in Java, coming from JNI

I've developed many apps with C++, JNI, NDK, but this is the first time it happens to me.

This is my Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_LIB_TYPE:=SHARED
OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on

include /Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk

include $(OPENCV_PATH)
LOCAL_MODULE    := libParameters
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/atmosphereFunctions/curl
LOCAL_C_INCLUDES += $(LOCAL_PATH)/atmosphereFunctions/Solarlib
LOCAL_C_INCLUDES += $(LOCAL_PATH)/coreFunctions

LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
LOCAL_MODULE    := libParameters
LOCAL_MODULE_NAME    := Parameters
LOCAL_SRC_FILES := androidClass.cpp coreFunctions/parameters.cpp atmosphereFunctions/atmosphere.cpp atmosphereFunctions/Solarlib/Solarlib.cpp
LOCAL_LDLIBS     += -llog -ldl
LOCAL_CPPFLAGS    := -std=c++11
LOCAL_CFLAGS    := -std=c++11 -w

CFLAGS=-w -g -Wall -Wextra -std=c++11 -Wno-write-strings ../../include/boost

LOCAL_SHARED_LIBRARIES := libopencv_java
LOCAL_STATIC_LIBRARIES := libcurl

include $(BUILD_SHARED_LIBRARY)

My Application.mk :

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a mips x86

APP_CPPFLAGS += -std=gnu++0x
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -DDEBUG
APP_CPPFLAGS += -std=c++11
APP_CPPFLAGS += -Wno-error=format-security

APP_CFLAGS := -std=c++11
NDK_TOOLCHAIN_VERSION := 4.8
LOCAL_C_INCLUDES += ${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/include

APP_USE_CPP0X := true

My androidClass.h

#include <jni.h>

#include "Parameters.h"

#ifdef __cplusplus
extern "C" {
#endif

    JNIEXPORT jstring JNICALL Java_com_example_Parameters_getParameters(JNIEnv * env, jclass, jint GMT, jfloat lat, jfloat lon, jfloat par, jstring fpath);

#ifdef __cplusplus
}
#endif

and this is the function inside androidClass.cpp :

JNIEXPORT jstring JNICALL Java_com_example_Parameters_getParameters(JNIEnv * env, jclass, jint GMT, jfloat lat, jfloat lon, jfloat par, jstring fpath) {

         return (jstring)"hey!";

}

then in my class Parameters.java (located at com.example.Parameters ) I set:

public static native String getParameters(int GMT, float lat, float lon, float par, String fpath);

and when I call it (I'm calling it from another package, since it's public static ):

java.lang.UnsatisfiedLinkError: Native method not found: com.example.Parameters.getParameters:(IFFFLjava/lang/String;)Ljava/lang/String;

what am I doing wrong here?

Thank you very much in advance.

It was really my fault.

I've always coded C++ libraries for only 1 activity (tests, eventual libraries) and I thought it was residing statically in memory, but I had to call again System.loadLibrary("...") which I didn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM