javamavenjenkinsjava-native-interfaceusb4java

JNI Dependencies and cross-platform build


I'm currently working for a project for which I need to detect whether an Oculus device is plugged or not.

I do so using the usb4java library usb4java.

<dependency> <groupId>org.usb4java</groupId> <artifactId>usb4java-javax</artifactId> <version>1.2.0</version> </dependency>

I want to build my program using Maven and Jenkins, which are installed on a ubuntu server, but I'm facing a problem with this library: if my program is built using this machine, my function is not working, but if I compile it on windows, my function is working like a charm.

Here is the function I use :

if (hub == null) {
        UsbServices services = UsbHostManager.getUsbServices();
        hub = services.getRootUsbHub();
    }
    //List all the USBs attached
    List devices = hub.getAttachedUsbDevices();
    Iterator iterator = devices.iterator();
    boolean res = false;
    while (iterator.hasNext()) {
        UsbDevice device = (UsbDevice) iterator.next();
        UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
        if (device.isUsbHub()) {
            res = res || isOculusPlugged((UsbHub) device);
        }
        else {
            try {
                if (desc.idVendor() == 10291) {
                    res = true;
                }
            } catch (NullPointerException ignored) {}
        }
    }

I get not error whatsoever, but the detection is just not working (res is always false) with the linux-built version.

I checked and all JNI libs including Windows is in the JAR-With-Dependencies I'm running.

Thanks for your help, Lucas


Solution

  • Turns out it was a problem of path