0

I followed this tutorial to use JNI with gradle project.

But , I have this ERROR.

Then , I followed this project to use jni with gradle project.

But , I have this ERROR.

I want to use JNI with gradle project to build native lib for windows, linux and mac.

How can I use JNI with gradle ?

Give a simple JNI tutorial with gradle.

  • By itself, Gradle does not know to generate header files for Java files with `native` methods – Botje Aug 11 '21 at 09:37
  • How Can I solve this following issue ? https://github.com/vladsoroka/GradleJniSample/issues/4 –  Aug 11 '21 at 11:22

1 Answers1

0

The Gradle Java plugin – by default – generates header files for any Java files that contain native methods.

The default output path is ${project.buildDir}/generated/sources/headers/${sourceDirectorySet.name}/${sourceSet.name}, so for the gcj project linked from your first link, I get the following file:

./build/generated/sources/headers/java/main/HelloWorld.h

In order to make the Gradle cpp plugin find that, you need to set its include search path to (a part of) the above path.

Botje
  • 26,269
  • 3
  • 31
  • 41
  • I am new to JNI . I still can't understand what you say about? Gradle file : https://github.com/vladsoroka/GradleJniSample/blob/master/build.gradle if run 'test' in gradle the output comes 'Helloworld'. But , My doubt is how can I run this in Main class. Project : https://github.com/vladsoroka/GradleJniSample and my issue : https://github.com/vladsoroka/GradleJniSample/issues/4 –  Aug 11 '21 at 14:11
  • You need to also set the `java.library.path` property when you run the program normally. – Botje Aug 11 '21 at 14:19
  • How can I set `java.library.path` property? –  Aug 11 '21 at 14:22
  • I tried this below ans but same error occurs `task local { run { systemProperty "java.library.path", "local" } } bootRun.mustRunAfter local` Then run gradle command as: `gradle bootRun local` project link : github.com/vladsoroka/GradleJniSample –  Aug 11 '21 at 14:46
  • Sorry, your question has nothing to do with JNI, beyond the need to set this one property. I tried my best to help you but I don't know how to solve the underlying Gradle problem. – Botje Aug 11 '21 at 14:50