How to sign dylib to be able to use Java JNI on Mac OS 15

Hi, I'm doing Java 22 experiments with open source package "wgpu-macos-aarch64-release" on my Mac M3.

This library contains a .dylib file and a .a file.

In Java you can load native dynamic libraries using JNI. I used that in the past. Now in MacOS 15 this stopped working.

Currently, I compile my Java file and run the binary file on the command line, including the library directory. The application would load the library from that directory. This should normally works but the library is not loaded.

After some investigation it seems the .dylib is rejected by MacOS.

Calling

spctl --assess --verbose=4 libwgpu_native.dylib

gives libwgpu_native.dylib: rejected

without any extra reason message.

Using sudo xattr -rd com.apple.quarantine libwgpu_native.dylib doesn't solve the problem.

I also can't "accept" it in "Privacy & Security" because it's run as a command line call.

I know that code signing should be done for "complete" applications. But these are just experiments and working with single dynamic libraries.

How should this be done, to be able to load those libraries in a Java command line program? Or in general, how can you load an unsigned dylib in an application (apart from using Java as a tool).

Kr, J

Answered by Aspixx in 826084022

Hi Quinn,

well you put me on the right path. With a small python program using dlopen I could verify I could load the library. So something else was wrong.

After some digging and experimenting, it seemed that I had to open "wgpu_native" instead of "libwgpu_native". The "lib" prefix is also considered part of the OS specific library name... sighs

So my problem is solved.

Thank you !

Kr, J

Normally, Unix-y programs like Java load code dynamically using dlopen and friends. If that fails, you can call dlerror to learn more about the failure. Are you able to access that error in this case? If so, please post it here because it’s likely to contain useful hints.

ps Your spctl and System Settings techniques are only relevant if the coed is blocked by Gatekeeper. I suspect something else is going on here.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Hi Quinn,

well you put me on the right path. With a small python program using dlopen I could verify I could load the library. So something else was wrong.

After some digging and experimenting, it seemed that I had to open "wgpu_native" instead of "libwgpu_native". The "lib" prefix is also considered part of the OS specific library name... sighs

So my problem is solved.

Thank you !

Kr, J

How to sign dylib to be able to use Java JNI on Mac OS 15
 
 
Q