diff --git a/java/java.gradle b/java/java.gradle index e3f2883080..23832de011 100644 --- a/java/java.gradle +++ b/java/java.gradle @@ -36,9 +36,11 @@ jar { model { binaries { withType(SharedLibraryBinarySpec) { binary -> - from(file(binary.sharedLibraryFile)) { - into getPlatformPath(binary) - } + // Only include the native file if not cross compiling to the roboRIO + if (!project.isArm || project.hasProperty('compilerPrefix')) + from(file(binary.sharedLibraryFile)) { + into getPlatformPath(binary) + } } } } diff --git a/java/src/edu/wpi/cameraserver/CameraServerJNI.java b/java/src/edu/wpi/cameraserver/CameraServerJNI.java index 13589b0312..4f69493ad7 100644 --- a/java/src/edu/wpi/cameraserver/CameraServerJNI.java +++ b/java/src/edu/wpi/cameraserver/CameraServerJNI.java @@ -20,53 +20,53 @@ public class CameraServerJNI { static { if (!libraryLoaded) { try { - String osname = System.getProperty("os.name"); - String resname; - if (osname.startsWith("Windows")) - resname = "/Windows/" + System.getProperty("os.arch") + "/"; - else - resname = "/" + osname + "/" + System.getProperty("os.arch") + "/"; - //System.out.println("platform: " + resname); - if (osname.startsWith("Windows")) - resname += "cameraserver.dll"; - else if (osname.startsWith("Mac")) - resname += "libcameraserver.dylib"; - else - resname += "libcameraserver.so"; - InputStream is = CameraServerJNI.class.getResourceAsStream(resname); - if (is != null) { - // create temporary file - if (System.getProperty("os.name").startsWith("Windows")) - jniLibrary = File.createTempFile("CameraServerJNI", ".dll"); - else if (System.getProperty("os.name").startsWith("Mac")) - jniLibrary = File.createTempFile("libCameraServerJNI", ".dylib"); + System.loadLibrary("cameraserver"); + } catch (UnsatisfiedLinkError e) { + try { + String osname = System.getProperty("os.name"); + String resname; + if (osname.startsWith("Windows")) + resname = "/Windows/" + System.getProperty("os.arch") + "/"; else - jniLibrary = File.createTempFile("libCameraServerJNI", ".so"); - // flag for delete on exit - jniLibrary.deleteOnExit(); - OutputStream os = new FileOutputStream(jniLibrary); + resname = "/" + osname + "/" + System.getProperty("os.arch") + "/"; + System.out.println("platform: " + resname); + if (osname.startsWith("Windows")) + resname += "cameraserver.dll"; + else if (osname.startsWith("Mac")) + resname += "libcameraserver.dylib"; + else + resname += "libcameraserver.so"; + InputStream is = CameraServerJNI.class.getResourceAsStream(resname); + if (is != null) { + // create temporary file + if (System.getProperty("os.name").startsWith("Windows")) + jniLibrary = File.createTempFile("CameraServerJNI", ".dll"); + else if (System.getProperty("os.name").startsWith("Mac")) + jniLibrary = File.createTempFile("libCameraServerJNI", ".dylib"); + else + jniLibrary = File.createTempFile("libCameraServerJNI", ".so"); + // flag for delete on exit + jniLibrary.deleteOnExit(); + OutputStream os = new FileOutputStream(jniLibrary); - byte[] buffer = new byte[1024]; - int readBytes; - try { - while ((readBytes = is.read(buffer)) != -1) { - os.write(buffer, 0, readBytes); + byte[] buffer = new byte[1024]; + int readBytes; + try { + while ((readBytes = is.read(buffer)) != -1) { + os.write(buffer, 0, readBytes); + } + } finally { + os.close(); + is.close(); } - } finally { - os.close(); - is.close(); - } - try { System.load(jniLibrary.getAbsolutePath()); - } catch (UnsatisfiedLinkError e) { + } else { System.loadLibrary("cameraserver"); } - } else { - System.loadLibrary("cameraserver"); + } catch (IOException ex) { + ex.printStackTrace(); + System.exit(1); } - } catch (IOException ex) { - ex.printStackTrace(); - System.exit(1); } libraryLoaded = true; } diff --git a/publish.gradle b/publish.gradle index d8c65a5102..d16425a50a 100644 --- a/publish.gradle +++ b/publish.gradle @@ -45,7 +45,12 @@ publishing { artifact nat.cameraserverJavadoc } if (project.buildArm) { - artifact project('arm').jar + def camArm = project('arm') + artifact camArm.jar + // If the library is not embedded include it in the repo + if (!project.hasProperty('compilerPrefix')) { + artifact camArm.cameraserverZip + } } if (!OperatingSystem.current().isWindows()) { if (project.hasProperty('makeDesktop')) {