Skip to content

Commit 5607026

Browse files
committed
Add article for JVM MSVC runtime error
1 parent 04f6560 commit 5607026

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

source/docs/software/advanced-gradlerio/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ GradleRIO is the mechanism that powers the deployment of robot code to the roboR
1212
deploy-git-data
1313
compiler-args
1414
profiling-with-visualvm
15-
15+
jvm-runtime
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# JVM Runtime error
2+
3+
Programs compiled with Microsoft Visual C++ (MSVC) require a MSVC runtime that is equal to or newer then the newest library being executed. WPILib is compiled with a recent version of MSVC.
4+
5+
In the past, this hasn’t really been used, but a change in the runtime last year actually took advantage of this requirement.
6+
7+
Most JDKs ship with an MSVC runtime, and many of them are old. Additionally, many of them don’t actually include the full runtime. Both of these are a problem, as all the JNI libraries loaded by WPILib both use a lot of the runtime, and are compiled against basically the newest runtime.
8+
9+
For the JDK shipped with WPILib, the newest runtime is installed to ensure this issue isn't run into. But other JDKs will fail. So in 2025, much more important than prior years, the WPILib JDK needs to be used.
10+
11+
The following error will be seen if a JDK with an incompatible MSVC runtime is used:
12+
13+
```console
14+
> Task :simulateJavaRelease FAILED
15+
If you receive errors loading the JNI dependencies, make sure you have the latest Visual Studio C++ Redstributable installed.
16+
That can be found at https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
17+
Exception in thread "main" edu.wpi.first.util.MsvcRuntimeException: Invalid MSVC Runtime Detected.
18+
Expected at least 14.40, but found 14.29
19+
JVM Location: C:\Program Files\Amazon Corretto\jdk21.0.5_11\bin\java.exe
20+
Runtime DLL Location: C:\Program Files\Amazon Corretto\jdk21.0.5_11\bin\msvcp140.dll
21+
See https://wpilib.org/jvmruntime for more information
22+
23+
at edu.wpi.first.util.WPIUtilJNI.checkMsvcRuntime(Native Method)
24+
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:470)
25+
at frc.robot.Main.main(Main.java:23)
26+
27+
FAILURE: Build failed with an exception.
28+
```
29+
30+
## Setting Gradle to use WPILib JDK
31+
32+
This is not necessary if using the WPILib VS Code, which is the supported way to run. The following methods may be used for other users.
33+
34+
Ensure you've :doc:`installed WPILib </docs/zero-to-robot/step-2/wpilib-setup>` before proceeding.
35+
36+
### Commandline Parameter
37+
38+
To ensure that Gradle uses the WPILib JDK, you must set :code:`org.gradle.java.home` to the WPILib JDK. This can be done by passing a parameter to gradle (where YEAR is the current WPILib installation):
39+
40+
```console
41+
gradlew -Dorg.gradle.java.home="C:\\Users\\Public\\wpilib\\YEAR\\jdk" ...
42+
```
43+
44+
### gradle.properties
45+
46+
It can also be done by putting ``gradle.properties`` in the project root with the following contents (where YEAR is the current WPILib installation):
47+
48+
.. warning:: This will only work if you only use your project on Windows, as the location is hardcoded to the location on Windows.
49+
50+
```text
51+
org.gradle.java.home=C:\\Users\\Public\\wpilib\\YEAR\\jdk
52+
```
53+
54+
### IDE
55+
56+
Some IDEs have a method to set the JDK used. Consult the documentation for your IDE.

0 commit comments

Comments
 (0)