How to create a JNI task in gradle?


(kavin kankeshwar) #1

There is a java library which depends on some c++ libraries using JNI, So when compiling the c++ libraries header files need to be created using javah

In ant we can do the following and it works. Wanted to find a “gradle’ish” way to do the same.

<target name="jni" depends="compile">
    <javah
        classpath="${build}"
        outputfile="../src/jni/jni_headers.h"
        class="com.a.b.c.Class"/>
 </target>

found something similar here: https://github.com/rklaren/GradleJNI/blob/master/build.gradle#L42-L55 but it says “hack” and is couple of years old so, want to check if there is a cleaner way to do it.


(Peter Niederwieser) #2

Gradle doesn’t currently ship with a ‘Javah’ task type. In such a case, using an existing Ant task (of course from a Gradle build script) is a good option, and hence it’s the first thing I’d try. If you wanted to take this to the next level, you could write a Gradle task class that calls the Ant task internally.