mardi 14 avril 2020

UnsatisfiedLinkError JNI method

I've done JNI stuff before, so I'm not totally new to it, but I'm getting an UnsatisfiedLinkError that's foxing me.

The error indicates that the method signature is wrong, rather than it not being able to find the library:

java.lang.UnsatisfiedLinkError: com.mycompany.ExampleGenerator.generate(Ljava/lang/String;Z)Lcom/mycompany/Example;
    at com.mycompany.ExampleGenerator.generate(Native Method)

My Java class:

package com.mycompany;

import com.mycompany.exceptions.GenerationFailure;

public class ExampleGenerator {

    public native Example generate(String url, boolean scramble) throws GenerationFailure;

    static {
        System.loadLibrary("example_jni");
    }

}

My .hpp file:

#include <jni.h>

#ifndef _Included_com_mycompany_ExampleGenerator
#define _Included_com_mycompany_ExampleGenerator
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jobject JNICALL Java_com_mycompany_ExampleGenerator_generate(JNIEnv *env, jobject, jstring url, jboolean scramble);
#ifdef __cplusplus
}
#endif
#endif

My implementation signature (.cpp file):

#ifndef _Included_com_mycompany_ExampleGenerator
#define _Included_com_mycompany_ExampleGenerator
#ifdef __cplusplus
extern "C" {
#endif

  JNIEXPORT jobject JNICALL Java_com_mycompany_ExampleGenerator_generate(JNIEnv *env, jobject, jstring url, jboolean scramble)
{
...
}



#ifdef __cplusplus
}
#endif
#endif

I can't see what's going wrong here. Maybe I've been looking at it for too long?! Any help appreciated.

Maybe I don't need the #ifndef _Included_com_mycompany_ExampleGenerator in both the header and the cpp file? (I haven't written a public header for JNI stuff I've done until now, so this is the new bit for me)

Aucun commentaire:

Enregistrer un commentaire