Kotlin: wpiHaljni could not be loaded from path or an embedded resource and Non-functioning Robot

Hello all!

I’ve been investigating the wonderful language of Kotlin and got to the point where I wanted to see how far I have come. So, I powered up my robot, built, and deployed, which all processed successfully, but when I enabled my robot, it did nothing, and died right away. It is probably important to say that I used to run Python as well. Anyway, I checked the log and their were no notable errors. (Unfortunately, do not have a capture of the log)

However, when I ran Main.kt, I received the following error:

/usr/lib/jvm/java-13-openjdk/bin/java -javaagent:/usr/share/idea/lib/idea_rt.jar=38727:/usr/share/idea/bin -Dfile.encoding=UTF-8 -classpath /home/coder/code/kobot/TheKobot/Kobot/build/classes/kotlin/main:/home/coder/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.3.4/21598c7ceabbcafb953cd151cd5ad44615a253c0/kotlinx-coroutines-core-1.3.4.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.71/898273189ad22779da6bed88ded39b14cb5fd432/kotlin-stdlib-1.3.71.jar:/home/coder/.gradle/caches/modules-2/files-2.1/com.kauailabs.navx.frc/navx-java/3.1.413/26937992e7c7f05ce87e408a5e18d062942612fa/navx-java-3.1.413.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.wpilibj/wpilibj-java/2020.3.2/e33bd477dcab11dbc9e5d4c914f79eebc09911c3/wpilibj-java-2020.3.2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.ntcore/ntcore-java/2020.3.2/a583d69b41f2bf688a3557cfdff2a656ddf9fa3/ntcore-java-2020.3.2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.wpiutil/wpiutil-java/2020.3.2/f165d2000ed73699bec8c5515b892e7d92f75f6b/wpiutil-java-2020.3.2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.thirdparty.frc2020.opencv/opencv-java/3.4.7-2/567376dfff9299972841aa5bf84116dacb931016/opencv-java-3.4.7-2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.cscore/cscore-java/2020.3.2/a477b4e78faf18c1d550e2afd9d54d90b3630123/cscore-java-2020.3.2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.cameraserver/cameraserver-java/2020.3.2/5dcb974185170ce9cc6b88da2014c35c245382e8/cameraserver-java-2020.3.2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.hal/hal-java/2020.3.2/332e398731529d7c38f2658ec6125b665251f5cd/hal-java-2020.3.2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.ejml/ejml-simple/0.38/1cfd0fbe2b23aa5af02e9681b011fd8040661039/ejml-simple-0.38.jar:/home/coder/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.10.0/1127c9cf62f2bb3121a3a2a0a1351d251a602117/jackson-databind-2.10.0.jar:/home/coder/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.10.0/e01cfd93b80d6773b3f757c78e756c9755b47b81/jackson-annotations-2.10.0.jar:/home/coder/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.10.0/4e2c5fa04648ec9772c63e2101c53af6504e624e/jackson-core-2.10.0.jar:/home/coder/.gradle/caches/modules-2/files-2.1/edu.wpi.first.wpilibNewCommands/wpilibNewCommands-java/2020.3.2/5873f2f6694d271e65edaeaad92a016510fe96fe/wpilibNewCommands-java-2020.3.2.jar:/home/coder/wpilib/2020/maven/com/ctre/phoenix/api-java/5.18.3/api-java-5.18.3.jar:/home/coder/wpilib/2020/maven/com/ctre/phoenix/wpiapi-java/5.18.3/wpiapi-java-5.18.3.jar:/home/coder/wpilib/2020/maven/com/revrobotics/frc/SparkMax-java/1.5.2/SparkMax-java-1.5.2.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.71/e71c3fef58e26affeb03d675e91fd8abdd44aa7b/kotlin-stdlib-common-1.3.71.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.ejml/ejml-fdense/0.38/426ac05f7fb9b87db4e854b8ded9be4fa57b69df/ejml-fdense-0.38.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.ejml/ejml-dsparse/0.38/4b2ed3b58a5c4b4292c1df0515e6cfb3e97f0f63/ejml-dsparse-0.38.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.ejml/ejml-ddense/0.38/3f64a356900f72951ffa0242e958b2acf18ac3a3/ejml-ddense-0.38.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.ejml/ejml-cdense/0.38/195fdce4a23d112b99a7f82f3a906ffff85a44de/ejml-cdense-0.38.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.ejml/ejml-zdense/0.38/70e655edf1ce505380e25c4622c9b0e3e07a1823/ejml-zdense-0.38.jar:/home/coder/.gradle/caches/modules-2/files-2.1/org.ejml/ejml-core/0.38/95493af53f603dfbbcd7d1d3df58b9d5a4c4e2b7/ejml-core-0.38.jar:/home/coder/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/3.0.2/25ea2e8b0c338a877313bd4672d3fe056ea78f0d/jsr305-3.0.2.jar frc.robot.Main
java.io.IOException: wpiHaljni could not be loaded from path or an embedded resource.
	attempted to load for platform /linux/x86-64/
Last Load Error: 
no wpiHaljni in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]

	at edu.wpi.first.wpiutil.RuntimeLoader.loadLibrary(RuntimeLoader.java:84)
	at edu.wpi.first.hal.JNIWrapper.<clinit>(JNIWrapper.java:38)
	at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:316)
	at frc.robot.Main$Companion.main(Main.kt:31)
	at frc.robot.Main.main(Main.kt)

So, I did some research, but am frankly a little troubled, as the resources I found were in Java, and I am not exactly sure how or if I can implement those solutions. I am also not sure if this is what is not making it run. I personally figure that this is not the issue from the other threads I’ve seen, although cannot be sure.

Any advice on where to look at my failing robot or ideas on how to solve this issue is much appreciated.

Thanks!

When you run Main.kt or Main.java directly from IntelliJ or VS Code or whatever IDE you use, it tries to run it without the correct dependencies. Unless you do some setup in your IDE, running the main method is going to crash. If you want to simulate it on your computer, you can either start the simulation in the standard WPI way with VS Code, or you can run ./gradlew simulateJava from the command line.

If the program did crash, I’m certain there would be logs somewhere on the Driver Station or even in the rio log if you are running that on your computer. We will definitely need some logs to help understand what the problem is. If you are able to, putting your code on GitHub would be helpful for us to debug the problem.

So the ./gradlew simulateJava did work, however it did not fail. I will fetch some logs next time I can as well. Here is the link to the repo. Thanks!

This is expected. As said above, if you just try to run the kotlin file directly, it will fail, as there is setup needed to ensure all the dependencies exist correctly. ./gradlew simulateJava is the supported way to run code on desktop, and works just fine with kotlin.