I’m trying to use Gradle to build an application that uses JOGL. I have specified the following dependencies:
dependencies {
compile 'org.jogamp.jogl:jogl-all:2.+'
compile 'org.jogamp.jogl:jogl-all:2.+:natives-macosx-universal'
compile 'org.jogamp.gluegen:gluegen-rt:2.+'
compile 'org.jogamp.gluegen:gluegen-rt:2.+:natives-macosx-universal'
}
Gradle resolves these dependencies, and the project builds fine. Problems arise, however, when I try to run my application, as it crashes with the following stack trace:
Catched ZipException: error in opening zip file, while TempJarCache.bootstrapNativeLib() of jar:file:/Users/private/.gradle/caches/artifacts-26/filestore/org.jogamp.gluegen/gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/gluegen-rt-2.0.2-natives-macosx-universal.jar!/ (file:/Users/private/.gradle/caches/artifacts-26/filestore/org.jogamp.gluegen/gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/ + gluegen-rt-2.0.2-natives-macosx-universal.jar)
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /System/Library/Frameworks/gluegen-rt.Framework/gluegen-rt
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1706)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1020)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:468)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:63)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:94)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:332)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$1.run(Platform.java:210)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:173)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
at org.aeriksson.plotter.renderer.Window.createCanvas(Window.java:38)
at org.aeriksson.plotter.renderer.Window.init(Window.java:29)
at org.aeriksson.plotter.Main.main(Main.java:20)
This seems to occur since jogl-all-2.0.2.jar tries to load jogl-all-2.0.2-natives-macosx-universal.jar at runtime, but can not find it since Gradle places these two files in different directories (gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/ vs. gluegen-rt/2.0.2/jar/7de4fb110a95f67c1cc1e122d508cd63e137e2eb/).
As mentioned in http://issues.gradle.org/browse/GRADLE-2553, this problem can be avoided by copying jogl-all-2.0.2-natives-macosx-universal.jar to the gluegen-rt/2.0.2/jar/33a869ad60f109f6743be86513c6d150e9f732a7/ directory (and doing the same thing for JOGL). However, this does not seem like a very elegant or robust solution.
Is there a better way to ensure that the libraries are loaded correctly (for instance, by forcing the jars to be placed in the same directory through build.gradle)?