question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.UnsatisfiedLinkError on Apple macOS Big Sur (Apple Silicon)

See original GitHub issue

On a project with sbt-dotenv version 2.1.204, there seems to be an issue during sbt startup. I’m getting an java.lang.UnsatisfiedLinkError exception on a machine running macOS Big Sur version 11.2.2 (20D80). The same project is working on an Intel machine with the exact same OS version.

Java version of the non working machine:

openjdk 11.0.10 2021-01-19 LTS
OpenJDK Runtime Environment Zulu11.45+27-CA (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM Zulu11.45+27-CA (build 11.0.10+9-LTS, mixed mode)

The exception that occurs is the following:

[info] .env detected (fileName=.env). About to configure JVM System Environment with new map
java.lang.UnsatisfiedLinkError: /Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp: dlopen(/Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp, 1): no suitable image found.  Did find:
	/Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp: no matching architecture in universal wrapper
	/Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp: no matching architecture in universal wrapper
	at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
	at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442)
	at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498)
	at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2627)
	at java.base/java.lang.Runtime.load0(Runtime.java:768)
	at java.base/java.lang.System.load(System.java:1837)
	at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1018)
	at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:988)
	at com.sun.jna.Native.<clinit>(Native.java:195)
	at au.com.onegeek.sbtdotenv.NativeEnvironmentManager$PosixNativeEnvironmentManagerImpl$PosixEnvironmentLibC.<clinit>(NativeEnvironmentManager.java:51)
	at au.com.onegeek.sbtdotenv.NativeEnvironmentManager$PosixNativeEnvironmentManagerImpl.<init>(NativeEnvironmentManager.java:59)
	at au.com.onegeek.sbtdotenv.NativeEnvironmentManager.getInstance(NativeEnvironmentManager.java:80)
	at au.com.onegeek.sbtdotenv.NativeEnvironmentManager.setEnv(NativeEnvironmentManager.java:87)
	at au.com.onegeek.sbtdotenv.SbtDotenv$.applyEnvironment(SbtDotenv.scala:92)
	at au.com.onegeek.sbtdotenv.SbtDotenv$.$anonfun$configureEnvironment$2(SbtDotenv.scala:75)
	at scala.Option.fold(Option.scala:251)
	at au.com.onegeek.sbtdotenv.SbtDotenv$.configureEnvironment(SbtDotenv.scala:75)
	at au.com.onegeek.sbtdotenv.SbtDotenv$autoImport$.$anonfun$dotEnv$1(SbtDotenv.scala:43)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.Project$.setProject(Project.scala:499)
	at sbt.BuiltinCommands$.doLoadProject(Main.scala:947)
	at sbt.BuiltinCommands$.$anonfun$loadProjectImpl$2(Main.scala:885)
	at sbt.Command$.$anonfun$applyEffect$4(Command.scala:150)
	at sbt.Command$.$anonfun$applyEffect$2(Command.scala:145)
	at sbt.Command$.process(Command.scala:189)
	at sbt.MainLoop$.$anonfun$processCommand$5(MainLoop.scala:243)
	at scala.Option.getOrElse(Option.scala:189)
	at sbt.MainLoop$.process$1(MainLoop.scala:243)
	at sbt.MainLoop$.processCommand(MainLoop.scala:276)
	at sbt.MainLoop$.$anonfun$next$5(MainLoop.scala:163)
	at sbt.State$StateOpsImpl$.runCmd$1(State.scala:289)
	at sbt.State$StateOpsImpl$.process$extension(State.scala:325)
	at sbt.MainLoop$.$anonfun$next$4(MainLoop.scala:163)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
	at sbt.MainLoop$.next(MainLoop.scala:163)
	at sbt.MainLoop$.run(MainLoop.scala:144)
	at sbt.MainLoop$.$anonfun$runWithNewLog$1(MainLoop.scala:119)
	at sbt.io.Using.apply(Using.scala:27)
	at sbt.MainLoop$.runWithNewLog(MainLoop.scala:112)
	at sbt.MainLoop$.runAndClearLast(MainLoop.scala:66)
	at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:51)
	at sbt.MainLoop$.runLogged(MainLoop.scala:42)
	at sbt.StandardMain$.runManaged(Main.scala:191)
	at sbt.xMain$.$anonfun$run$8(Main.scala:102)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
	at scala.Console$.withIn(Console.scala:230)
	at sbt.internal.util.Terminal$.withIn(Terminal.scala:560)
	at sbt.internal.util.Terminal$.$anonfun$withStreams$1(Terminal.scala:350)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
	at scala.Console$.withOut(Console.scala:167)
	at sbt.internal.util.Terminal$.$anonfun$withOut$2(Terminal.scala:550)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
	at scala.Console$.withErr(Console.scala:196)
	at sbt.internal.util.Terminal$.withOut(Terminal.scala:550)
	at sbt.internal.util.Terminal$.withStreams(Terminal.scala:350)
	at sbt.xMain$.run(Main.scala:86)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at sbt.internal.XMainConfiguration.run(XMainConfiguration.scala:83)
	at sbt.xMain.run(Main.scala:46)
	at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:111)
	at xsbt.boot.Launch$.withContextLoader(Launch.scala:131)
	at xsbt.boot.Launch$.run(Launch.scala:111)
	at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:37)
	at xsbt.boot.Launch$.launch(Launch.scala:120)
	at xsbt.boot.Launch$.apply(Launch.scala:20)
	at xsbt.boot.Boot$.runImpl(Boot.scala:56)
	at xsbt.boot.Boot$.main(Boot.scala:18)
	at xsbt.boot.Boot.main(Boot.scala)
[error] java.lang.UnsatisfiedLinkError: /Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp: dlopen(/Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp, 1): no suitable image found.  Did find:
[error] 	/Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp: no matching architecture in universal wrapper
[error] 	/Users/user/Library/Caches/JNA/temp/jna3373323925107818614.tmp: no matching architecture in universal wrapper
[error] Use 'last' for the full log.
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
nikosparacommented, Sep 15, 2021

Picking up from nkgm’s comment, I think there is a cleaner solution: use the jna.boot.library.path configuration option (ref). This option lets you override the actual JNA jar used.

You have 2 options:

  • Set on each execution: this is local and affects only the JVM you are running. To use, simply add -Djna.boot.library.path=/path/to/libjnidispatch.jnilib to the Java command line (before the main class name of course). Several programs (e.g. servers) let you define special environment variables (e.g. JAVA_OPTS), you can utilize these.
  • Set globally: on my M1 I had to add the line export _JAVA_OPTIONS=-Djna.boot.library.path=/path/to/lib to ~/.bashrc (and make sure ~/.bash_profile is actually using it, e.g. contains the line . ~/.bashrc). Log out and back in and it is generally accessible, even from within IDEs (at least my installation of IntelliJ is picking it up, both from the sbt shell and when running programs directly).

To obtain the libjnidispatch.jnilib:

  1. First download jna-X.Y.Z.jar from the link nkgm provided
  2. Extract its contents somewhere (jar -xf jna-X.Y.Z.jar)
  3. Move com/sun/jna/darwin-aarch64/libjnidispatch.jnilib to a directory of your choice - the /path/to/lib above.

(thanks to mbablok for pointing out that we need the directory here, not the path to the file)

6reactions
nkgmcommented, Jul 26, 2021

This is fixed in jna-5.8.0, and even though sbt-dotenv is trying to use the latest version, sbt itself is on the older jna-5.5.0, so I’m guessing this is the cause of the problem.

If you don’t mind a little hackery, you can hunt down sbt’s own jna-5.5.0.jar and jna-platform-5.5.0.jar (in my case found under $HOME/.sbt/boot/scala-2.12.14/org.scala-sbt/sbt/1.5.5 and replace them with the latest jars found here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.UnsatisfiedLinkError on Apple macOS Big Sur ...
On a project with sbt-dotenv version 2.1.204, there seems to be an issue during sbt startup. I'm getting an java.lang.UnsatisfiedLinkError ...
Read more >
UnsatisfiedLinkError for M1 Macs while running Play server ...
Another issue that may produce this error is associated with how Apple changed the way system libraries are loaded in macOS 11 (Big...
Read more >
java.lang.UnsatisfiedLinkError: no suitable image found
I am developing an app using KMM and switched to a MacBook with the new M1 chip today. The android app builds and...
Read more >
Mac Big Sur version 11.0.1 java.lang.UnsatisfiedLinkError ...
Coding example for the question Mac Big Sur version 11.0.1 java.lang.UnsatisfiedLinkError: Unable to load library 'CoreFoundation'-Flutter.
Read more >
Can't run on M1 Mac - java.lang.UnsatisfiedLinkError
I can't use the SDK on an M1 Mac using IntellJ CE 2021.3. My build.gradle entry:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found