JavaFx on Apple Silicon / UnsatisfiedLinkError: Can't load library: libprism_es2.dylib

Viewed 94

I'm trying to build a JavaFx project using Maven, gradle, sbt, or similar on a MacOS system with an Apple Silicon chip, and I've encountered an error something like this:

UnsatisfiedLinkError: Can't load library: libprism_es2.dylib

What to do?

1 Answers

JavaFx does support Apple Silicon (aarch64) architecture starting from version 17-ea+8.

But you need to qualify the dependency with a classifier for the operating system and the architecture.

With Maven, the dependency should look something like this:

<!-- ... -->
<dependency>
  <groupId>org.openjfx</groupId>
  <artifactId>javafx-controls</artifactId>
  <version>18.0.2</version>
  <classifier>mac-aarch64</classifier>
</dependency>
<!-- ... -->

In gradle, the JavaFx Plugin version 0.0.11 or later will append the correct classifier:

plugins {
    // ...
    id( "org.openjfx.javafxplugin" ) version "0.0.13"
    // ...
}

In sbt, you would add the following to your build.sbt file:

lazy val myproject = ( project in file( "." ) )
  .settings(
    // ...
    libraryDependencies ++= Seq(
      //...
      "org.openjfx" % "javafx-controls" % "18.0.2" classifier "mac-aarch64",
      //...
    )
    // ...
  )

With each of these build tools, you can do sophisticated stuff so that your build definition dynamically resolves which classifier to apply, regardless of the platform you're building for. But that's left as an exercise for the reader.

Note that although System.getProperty( "os.name" ) does not resolve to the exact text that org.openjfx uses to identify the target platform in its classifiers, System.getProperty( "os.arch" ) does resolve to the text aarch64 on an Apple Silicon computer.

Related