java. Lang. unsatisfiedlinkerror: no implementation was found because the library was not loaded
•
Java
When it says jnilibs and other libraries When the so file could not be loaded, I was trying to integrate a shared library written natively into my application
This is the C file
#include <string.h>
#include <jni.h>
#include <dummy.h>
JNIEXPORT jstring
Java_com_example_hellojni_HelloJni_DummyInit(jnienv*env,jobject thiz) {
dummy *handle;
char *msg;
int rc = dummy_init_from_id("ml",&handle,&msg);
if (rc == DUMMY_SUCCESS) {
return (*env)->NewStringUTF(env,"Init was successful");
} else {
return (*env)->NewStringUTF(env,msg);
}
}
JNIEXPORT void
Java_com_example_hellojni_HelloJni_DummySetSymbolsDir(jnienv *env,jobject thiz,jstring dir) {
dummy_set_symbols_dir(dir);
}
This is a java file
package com.example.hellojni;
import android.app.Activity;
import android.util.Log;
import android.widget.TextView;
import android.os.Bundle;
import java.io.File;
public class HelloJni extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
File f = new File(getAssets() + "/ml");
if (f.exists()) try {
System.out.println("Scheme exists");
} catch (Exception e) {
throw new RuntimeException(e);
}
String dir = f.getPath();
DummySetSymbolsDir(dir);
TextView tv = new TextView(this);
tv.setText(DummyInit());
setContentView(tv);
}
/*** Native Methods ***/
public native String DummyInit();
public native void DummySetSymbolsDir(String dir);
static {
try {
System.loadLibrary(("dummy"));
} catch (UnsatisfiedLinkError e) {
Log.e("JNI","Warning:Could not use dummy library");
}
try {
System.loadLibrary("libs/libpthead.so");
} catch (UnsatisfiedLinkError e) {
Log.e("JNI","Warning:Could not use lipthread library");
}
try {
System.loadLibrary("hello-jni");
} catch (UnsatisfiedLinkError e) {
Log.e("JNI","Warning:Could not use hello-jni library");
}
}
}
The exact error is as follows
FATAL EXCEPTION: main Process: com.example.hellojni,PID: 2558 java.lang.UnsatisfiedLinkError: No implementation found for void com.example.hellojni.HelloJni.DummySetSymbolsDir(java.lang.String) (tried Java_com_example_hellojni_HelloJni_DummySetSymbolsDir and Java_com_example_hellojni_HelloJni_DummySetSymbolsDir__Ljava_lang_String_2) at com.example.hellojni.HelloJni.DummySetSymbolsDir(Native Method) at com.example.hellojni.HelloJni.onCreate(HelloJni.java:34) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Android. The MK file is as follows
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello-jni LOCAL_SRC_FILES := hello-jni.c include $(BUILD_SHARED_LIBRARY)
If you need more information, please let me know thank you.
Solution
You may need to surround your code with an extern "C" block:
extern "C" {
Your JNIEXPORT functions
}
For C and C, you can:
#ifdef __cplusplus
extern "C" {
#endif
Your JNIEXPORT functions
#ifdef __cplusplus
}
#endif
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
