Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jnigen trying to run the example of Example sum method but exception #957

Closed
AuraCodez opened this issue Jan 30, 2024 · 4 comments
Closed

Comments

@AuraCodez
Copy link

AuraCodez commented Jan 30, 2024

For the example class that was provided in the video, I cloned the repository and did dart run jnigen_example:sum 14 9 but it is giving me a unhandled exception. Lookup for helper library build/jni_libs/libdartjni.dylib failed. Please ensure that dartjni shared library is built. Provided jni:setup script can be used to build the shared library.

Btw, I just was following the instructions from this thread. #672

git clone https://github.com/HosseinYousefi/jnigen_example
cd jnigen_example
dart run jni:setup -p jni -s src/example
javac java/dev/dart/Example.java
dart run jnigen_example:sum 17 25

at the dart run jni_setup -p jni -s src/example part I'm also getting cmake not found. I'm also running on MacOS.

@HosseinYousefi
Copy link
Member

HosseinYousefi commented Jan 30, 2024

You need to install CMAKE. https://cmake.org/download/

On macOS, you could use brew to install it.

@AuraCodez
Copy link
Author

I need to understand a few things here, do we need to run dart run jni setup everytime? It keeps saying could not find JNI missing java include path, java include path2 awt. I am thinking becuse of this, jnigen is not working in any of my apps

@AuraCodez
Copy link
Author

When i run the jni setup command(it fails), i run the javac thing and then run dart run jni_example:sum 17 25 gives me exception, saying lookup for helper library build/jni_lube/libdartjni.dylib failed. Ensure dartjni shared library is built

@HosseinYousefi
Copy link
Member

There is a requirements section in the docs that you can read: https://github.com/dart-lang/native/tree/main/pkgs/jnigen#requirements

To explain things further, jnigen is simply using ffi under the hood to call C function (and not Java directly), these C functions use JNI (Java Native Interface), to call Java methods.

       dartjni           jni
Dart -----------> C ------------> Java

Now Dart needs to have libdartjni.dylib (or dartjni.so on Linux, or ...) to call the C functions, and C needs to have access to libjni.dylib on the PATH to access Java methods.

Therefore you would need to build jni once, and have correct path to Java in your PATH environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants