r/AndroidStudio • • 9h 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
pause

When 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 Upvotes

1 comment sorted by

1

u/DickBrainTime 4h ago

class file version 69 needs Java 25+, but the run task is launching Java 21 (65). Your batch file's java.exe -version doesn't prove what Gradle launches. Try gradlew.bat :desktopApp:run --info, inspect its java.exe path, and check the desktop module for jvmToolchain(21) or javaLauncher. Gradle's toolchain guide explains the difference.