cyberbotics / webots

Webots Robot Simulator
https://cyberbotics.com
Apache License 2.0
3.21k stars 1.68k forks source link

Issue with Java on macOS M1 #5181

Open alexvena19 opened 2 years ago

alexvena19 commented 2 years ago

trying to run a Webots program, and the output is Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help. java.lang.UnsatisfiedLinkError: no JavaController in java.library.path: [/Applications/Webots.app/lib/controller/java]

I'm using a MacBook m1 pro, 64-bit version of java.

Screen Shot 2022-09-07 at 9 56 18 AM Screen%20Shot%202022-09-07%20at%209 24 38%20AM copy
omichel commented 2 years ago

Which version of Webots are you using?

alexvena19 commented 2 years ago

Webots R2022a.

omichel commented 2 years ago

Can you try with the latest nightly build of Webots R2022b? You can download it from https://github.com/cyberbotics/webots/releases/tag/nightly_5_9_2022 Webots R2022b introduces native support for M1 macs. It could be that the Java version you are using is built for M1 while the libController of Webots R2022a doesn't support M1, thus the error. Using Webots R2022b with M1 support should fix the problem. Let me know if that works.

alexvena19 commented 2 years ago

Can you try with the latest nightly build of Webots R2022b? You can download it from https://github.com/cyberbotics/webots/releases/tag/nightly_5_9_2022 Webots R2022b introduces native support for M1 macs. It could be that the Java version you are using is built for M1 while the libController of Webots R2022a doesn't support M1, thus the error. Using Webots R2022b with M1 support should fix the problem. Let me know if that works.

Sure I will try that. Which link of these do I download?

Screen Shot 2022-09-07 at 10 04 17 AM
omichel commented 2 years ago

webots-R2022b.dmg

alexvena19 commented 2 years ago

webots-R2022b.dmg

Still not working. I only downloaded the webots-R2022b.dmg

Screen Shot 2022-09-07 at 10 17 04 AM
omichel commented 2 years ago

Still not working. I only downloaded the webots-R2022b.dmg

Did you remove Webots R2022a and installed R2022b instead?

alexvena19 commented 2 years ago

Still not working. I only downloaded the webots-R2022b.dmg

Did you remove Webots R2022a and installed R2022b instead?

Yes, when I downloaded it it got replaced by R2022b

Screen Shot 2022-09-07 at 10 21 21 AM
omichel commented 2 years ago

Do controllers other than Java work for you (e.g., C, C++, Python)?

alexvena19 commented 2 years ago

Do controllers other than Java work for you (e.g., C, C++, Python)?

I just tried the python example, says I don't have it downloaded as this is a new laptop. I only need the java controller to work for using Webots.

alexvena19 commented 2 years ago

Do controllers other than Java work for you (e.g., C, C++, Python)?

I just tried the python example, says I don't have it downloaded as this is a new laptop. I only need the java controller to work for using Webots.

perhaps I am missing something else to download for java? I have the java 17 64-bit version running on this laptop as shown earlier

omichel commented 2 years ago

Is your Java version compiled for M1, Intel or both?

alexvena19 commented 2 years ago

Is your Java version compiled for M1, Intel or both?

I'm not sure, I assume M1. I downloaded java 17 from here: https://www.oracle.com/java/technologies/downloads/#java17

omichel commented 2 years ago

There are several versions there, some are arm64 (M1) and some are x64 (Intel). Which one did you get?

alexvena19 commented 2 years ago

There are several versions there, some are arm64 (M1) and some are x64 (Intel). Which one did you get?

arm64

alexvena19 commented 2 years ago

There are several versions there, some are arm64 (M1) and some are x64 (Intel). Which one did you get?

arm64 the x64 did not work when downloading on this computer

alexvena19 commented 2 years ago

update: I tried using cpp and it worked perfectly. must be a java issue?

Tom1072 commented 2 years ago

Hi, I have similar problem and it seems like ARM 64 JDK doesn't work well with SWIG. I tried with X86_64 JDK and things work without problem. Here's my jdk version.

❯ java --version
java 18.0.2.1 2022-08-18
Java(TM) SE Runtime Environment (build 18.0.2.1+1-1)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing
❯ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    18.0.2.1 (x86_64) "Oracle Corporation" - "Java SE 18.0.2.1" /Library/Java/JavaVirtualMachines/jdk-18.0.2.1.jdk/Contents/Home
linde9821 commented 1 year ago

Is there any news regarding this problem?

I currently try to get a setup working with Kotlin and Gradle. And I have the same issue.

Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.
java.lang.UnsatisfiedLinkError: no JavaController in java.library.path: /Applications/Webots.app/Contents/lib/controller/java
WARNING: 'KotlinTest' controller exited with status: 1.

My build.gradle.kts looks like this:

plugins {
    kotlin("jvm") version "1.7.20"
    application
}

repositories {
    mavenCentral()
}

tasks {
    val fatJar = register<Jar>("fatJar") {
        dependsOn.addAll(
            listOf(
                "compileJava",
                "compileKotlin",
                "processResources"
            )
        ) // We need this for Gradle optimization to work
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE
        manifest { attributes(mapOf("Main-Class" to application.mainClass)) } // Provided we set it up in the application plugin configuration
        val sourcesMain = sourceSets.main.get()
        val contents = configurations.runtimeClasspath.get()
            .map { if (it.isDirectory) it else zipTree(it) } +
                sourcesMain.output
        from(contents)
    }
    build {
        dependsOn(fatJar) // Trigger fat jar creation during build
    }
}

dependencies {
    // Align versions of all Kotlin components
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))

    // Use the Kotlin JDK 8 standard library.
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

    implementation(
        files(
            "/Applications/Webots.app/Contents/lib/controller/java/Controller.jar",
        )
    )
}

application {
    // Define the main class for the application.
    mainClass.set("KotlinTestKt")
}

I especially made sure that I use a X86_64 jvm as suggested by @Tom1072

daenenk commented 1 year ago

I'm using a MacBook with Intel CPU. When launching Webots by clicking on the icon in the Applications folder, and trying to use a Java controller, I also got the error java.lang.UnsatisfiedLinkError: no JavaController in java.library.path: [/Applications/Webots.app/lib/controller/java]. The solution for me was to launch Webots from the Terminal, with open -a "Webots" (after making sure that in that Terminal JAVA_HOME has been set). Then it worked. I tested several JVMs:

2Gameboyz commented 1 year ago

Tried to make Webots work on my M1 macbook. I tested different java versions and got two different outputs returned:

Error 1: Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help. java.lang.UnsatisfiedLinkError: JavaController (Not found in java.library.path)

Error 2: Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help. java.lang.UnsatisfiedLinkError: /Applications/Webots.app/Contents/lib/controller/java/libJavaController.jnilib: dlopen(/Applications/Webots.app/Contents/lib/controller/java/libJavaController.jnilib, 0x0001): Library not loaded: @rpath/Contents/lib/controller/libController.dylib Referenced from: <1230A4CD-5754-3EB5-A093-A02362087696> /Applications/Webots.app/Contents/lib/controller/java/libJavaController.jnilib Reason: tried: '/Applications/Webots.app/Contents/lib/controller/java/../../../Contents/lib/controller/libController.dylib' (no such file), '/Applications/Webots.app/Contents/lib/controller/java/../../../Contents/lib/controller/libController.dylib' (no such file), '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/lib/server/./Contents/lib/controller/libController.dylib' (no such file), '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/lib/server/../Contents/lib/controller/libController.dylib' (no such file), ‚/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/./Contents/lib/controller/libControl

I tested the following jvm and jdk: Error 1 returned:

Error 2 returned:

koenyskout commented 7 months ago

Running webots R2023b, I also got Error 2 of @2Gameboyz when trying to run a Java controller on my Mac M1. Interestingly, the path /Applications/Webots.app/Contents/lib/controller/java/../../../Contents/lib/controller/libController.dylib mentioned in the error is missing one ../ in order to work (it goes to /Contents/Contents/lib). By adding a symlink ln -s . Contents in the /Applications/Webots.app/Contents folder, everything started working. So probably there is a wrong path configured somewhere in the build.