Problem with gradle build

Build does not complete. When I debug with --debug option, I get this error lines:

Looking for a different daemon…
2022-05-13T08:36:09.939+0530 [INFO] [org.gradle.launcher.daemon.client.DefaultDaemonConnector] Found daemon DaemonInfo{pid=6320, address=[490632dd-f1fa-40c5-b3ac-a17c4b7f49cd port:50902, addresses:[/127.0.0.1]], state=Idle, lastBusy=1652025049443, context=DefaultDaemonContext[uid=50a5d2b1-41ba-450e-98ed-9dd078e21ba1,javaHome=F:\Program Files\Android\Android Studio\jre,daemonRegistryDir=C:\Users\Admin.gradle\daemon,pid=6320,idleTimeout=10800000,priority=NORMAL,daemonOpts=-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:50896,–add-opens,java.base/java.util=ALL-UNNAMED,–add-opens,java.base/java.lang=ALL-UNNAMED,–add-opens,java.base/java.lang.invoke=ALL-UNNAMED,–add-opens,java.base/java.util=ALL-UNNAMED,–add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,–add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,–add-opens,java.base/java.nio.charset=ALL-UNNAMED,–add-opens,java.base/java.net=ALL-UNNAMED,–add-opens,java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1536m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]} however its context does not match the desired criteria.
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=C:\Program Files\Java\jdk-11.0.15.1,daemonRegistryDir=C:\Users\Admin.gradle\daemon,pid=5900,idleTimeout=null,priority=NORMAL,daemonOpts=–add-opens,java.base/java.util=ALL-UNNAMED,–add-opens,java.base/java.lang=ALL-UNNAMED,–add-opens,java.base/java.lang.invoke=ALL-UNNAMED,–add-opens,java.base/java.util=ALL-UNNAMED,–add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,–add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,–add-opens,java.base/java.nio.charset=ALL-UNNAMED,–add-opens,java.base/java.net=ALL-UNNAMED,–add-opens,java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1536m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=50a5d2b1-41ba-450e-98ed-9dd078e21ba1,javaHome=F:\Program Files\Android\Android Studio\jre,daemonRegistryDir=C:\Users\Admin.gradle\daemon,pid=6320,idleTimeout=10800000,priority=NORMAL,daemonOpts=-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:50896,–add-opens,java.base/java.util=ALL-UNNAMED,–add-opens,java.base/java.lang=ALL-UNNAMED,–add-opens,java.base/java.lang.invoke=ALL-UNNAMED,–add-opens,java.base/java.util=ALL-UNNAMED,–add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,–add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,–add-opens,java.base/java.nio.charset=ALL-UNNAMED,–add-opens,java.base/java.net=ALL-UNNAMED,–add-opens,java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1536m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]

I have tried the following:
a)Set JAVA_HOME in system variables(and restarted the box) to C:\Program Files\Java\jdk-11.0.15.1.
b)Set org.gradle.java.home=C:\Program Files\Java\jdk-11.0.15.1 in gradle.properties.
c) set JAVA_HOME in Edit Configurations tab to C:\Program Files\Java\jdk-11.0.15.1.
d) I even renamed the folder(for a while) “F:\Program Files\Android\Android Studio\jre” to “F:\Program Files\Android\Android Studio\jre11xxxdfge”.

This is the actual command line executed from .\gradlew.bat:
C:\Users\Admin\AndroidStudioProjects\arcore-android-sdk\samples\hello_ar_c>“C:\Program Files\Java\jdk-11.0.15.1\bin\java.exe” “-Xmx64m” “-Xms64m” "-D org.gr
adle.appname=gradlew" -classpath “C:\Users\Admin\AndroidStudioProjects\arcore-android-sdk\samples\hello_ar_c\gradle\wrapper\gradle-wrapper.jar” org.gradle.wrapp
er.GradleWrapperMain build

Command line:
Still, no luck. It keeps complaining with the above message. Where is the ‘DefaultDaemonContext’ for gradle loaded from? Anyway, it looks like a bug to me?