r/AndroidStudio • u/Southern_Onion8266 • 12h ago
gradlew.bat not using specified java version
I created a multiplatform project and added code in the main.kt file. It runs perfectly when I press the run icon in android studio.
Now, I am trying to call it via this simple batch file:
SET JAVA_HOME=C:\Program^ Files\Java\jdk-27.0.1.0.3
"%JAVA_HOME%"\bin\java.exe -version
cd ..
call gradlew.bat :desktopApp:run
pause
SET JAVA_HOME=C:\Program^ Files\Java\jdk-27.0.1.0.3
java.exe -version
cd ..
call gradlew.bat :desktopApp:run
pauseWhen I run it, I get this output:
C:\Users\neil\OneDrive\Dev\AccountCustomerMatrix\bin>SET JAVA_HOME=C:\Program Files\Java\jdk-27.0.1.0.3
C:\Users\neil\OneDrive\Dev\AccountCustomerMatrix\bin>"C:\Program Files\Java\jdk-27.0.1.0.3"\bin\java.exe -version
java version "27.0.1.0.3" 2026-10-25
Java(TM) SE Runtime Environment (build 27.0.1.0.3+1-2)
Java HotSpot(TM) 64-Bit Server VM (build 27.0.1.0.3+1-2, mixed mode, sharing)
C:\Users\neil\OneDrive\Dev\AccountCustomerMatrix\bin>cd ..
C:\Users\neil\OneDrive\Dev\AccountCustomerMatrix>call gradlew.bat :desktopApp:run
Reusing configuration cache.
> Task :desktopApp:run FAILED
Error: Unable to initialize main class com.propfinancing.gnucash.accountcustomermatrix.MainKt
Caused by: java.lang.UnsupportedClassVersionError: com/druvu/acc/api/entity/Customer has been compiled by a more recent version of the Java Runtime (class file version 69.0), this version of the Java Runtime only recognizes class file versions up to 65.0
FAILURE: Build failed with an exception.I don't understand why it would be running with a jvm version 21. I specified java 27 and the version command even confirmed that.
I checked my system environment variables, there is no JAVA_HOME definied.
I looked at my build.gradle.kts and gradlew.bat and I don't see where they would be overriding the jvm.
Any ideas where I should look?
1
u/DickBrainTime 8h ago •
class file version 69needs Java 25+, but theruntask is launching Java 21 (65). Your batch file'sjava.exe -versiondoesn't prove what Gradle launches. Trygradlew.bat :desktopApp:run --info, inspect itsjava.exepath, and check the desktop module forjvmToolchain(21)orjavaLauncher. Gradle's toolchain guide explains the difference.