Java/Objective-C JNI Library
You can open this sample inside an IDE using the IntelliJ native importer or Eclipse Buildship. |
This sample shows how a JNI library implemented in Java and Objective-C can be built with Gradle. The library has no dependencies, and the build has a minimal configuration.
build.gradle
plugins {
id 'java'
id 'dev.nokee.jni-library'
id 'dev.nokee.objective-c-language'
}
library.variants.configureEach {
sharedLibrary.linkTask.configure {
linkerArgs.add('-lobjc')
}
}
build.gradle.kts
plugins {
id("java")
id("dev.nokee.jni-library")
id("dev.nokee.objective-c-language")
}
library.variants.configureEach {
sharedLibrary.linkTask.configure {
linkerArgs.add("-lobjc")
}
}
To build the library:
$ ./gradlew assemble BUILD SUCCESSFUL 4 actionable tasks: 4 executed
The JNI library produced inside ./build/libs
directory:
$ ls ./build/libs/*.jar ./build/libs/java-objective-c-jni-library.jar
Since there is only one variant, the native component is included inside the main JAR:
$ jar tf ./build/libs/java-objective-c-jni-library.jar META-INF/ META-INF/MANIFEST.MF com/ com/example/ com/example/greeter/ com/example/greeter/NativeLoader.class com/example/greeter/Greeter.class libjava-objective-c-jni-library.dylib
For more information, see JNI Library Plugin and Objective-C Language Plugin reference chapters.