'Kotlin could not find the required JDK tools in the Java installation
When running ./gradlew clean build
I get following message:
> Task :compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
I have JDK, JAVA_HOME
is set properly, so is update-alternatives
.
# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
# update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/default-java/bin/java 1100 auto mode
1 /usr/lib/jvm/default-java/bin/java 1100 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/java 1 manual mode
3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Here's gradle build with stacktrace enabled:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileKotlin'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:74)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.execute(DefaultTaskExecutionGraph.java:143)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:40)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:40)
at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:24)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:46)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:49)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:40)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:33)
at org.gradle.initialization.DefaultGradleLauncher$ExecuteTasks.run(DefaultGradleLauncher.java:355)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.initialization.DefaultGradleLauncher.runTasks(DefaultGradleLauncher.java:219)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:124)
at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:77)
at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:74)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:154)
at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:38)
at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:96)
at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:74)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.run(RunAsBuildOperationBuildActionRunner.java:50)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:44)
at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:79)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:44)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:62)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:34)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:59)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:31)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:46)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:81)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.GradleException: Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
at org.jetbrains.kotlin.gradle.tasks.JarSearchingUtilKt.findToolsJar(jarSearchingUtil.kt:95)
at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:255)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
... 111 more
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context
at org.jetbrains.kotlin.gradle.tasks.JarSearchingUtilKt.findToolsJar(jarSearchingUtil.kt:92)
... 124 more
So from what I can see, it's failing during search for tools.jar
- which I have under /usr/lib/jvm/default-java/lib
, since the configured path is to JDK.
My gradle.build
- just in case:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
}
ext {
ktorVersion = "1.1.2"
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "io.ktor:ktor-server-netty:$ktorVersion"
implementation "io.ktor:ktor-jackson:$ktorVersion"
implementation "io.ktor:ktor-freemarker:$ktorVersion"
implementation "io.ktor:ktor-auth:$ktorVersion"
implementation "ch.qos.logback:logback-classic:1.2.3"
implementation 'io.github.microutils:kotlin-logging:1.6.22'
implementation 'org.koin:koin-ktor:2.0.0-beta-3'
implementation 'org.litote.kmongo:kmongo-coroutine:3.10.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
I'm truly at a loss, would appreciate some help.
If any more information is needed let me know and I'll do my best to provide it.
Solution 1:[1]
I solved a similar problem in MacOS (Big Sur). In my case I was running a React Native project and got the following error when trying to build to Android:
* What went wrong:
Execution failed for task ':bugsnag_react-native:compileDebugKotlin'.
> Kotlin could not find the required JDK tools in the Java installation '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home' used by G
radle. Make sure Gradle is running on a JDK, not JRE.
I followed this article for uninstalling the JRE on MacOS. Slightly modified to make the process reversible, here are the steps:
cd /Library/Internet\ Plug-Ins/
mv JavaAppletPlugin.plugin DELETED-JavaAppletPlugin.plugin
cd /Library/PreferencePanes/
mv JavaControlPanel.prefPane DELETED-JavaControlPanel.prefPane
When you receive Permission denied
use sudo
before commands.
I then cleared my Gradle folder. I don't know if this is necessary, but it worked for me:
rm -rf ~/.gradle
Finally, I rebuilt my project (react-native run-android
) and everything worked.
I'm not sure removing the JRE is the best solution since you may need the JRE for other things, but I have not noticed any ill effects. Also, it appears I already had a JDK installed which may not be true for all Mac users.
Since there are not any good answers on Stack Overflow that address this problem on MacOS, I figured I'd post my solution here.
Solution 2:[2]
android studio also offers jdk. If you specify that jdk as below, it will succeed
export PATH=$PATH:/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home/bin
export JAVA_HOME=/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home
Solution 3:[3]
Following MacOS update to Big Sur, I was seeing the same problem as Tom Aranda above. Upon further investigation, I came across this SO post and this led me to this radar. I wasn't happy removing the JRE as per Tom's answer and so have worked around my own install with details from the other posts.....
My previous declaration of JAVA_HOME
was in ~/.zshrc
as
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
but Big Sur appears to have updated the default JRE version to 1.8 also. So my JAVA_HOME needs to be more precise with its filtering.
% /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.251.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_241 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
And I now export as
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_241`
Now this isn't ideal as it'll break the next time I update the JDK.
As per the details in the radar and the other SO post I also need to ensure that any existing exported JAVA_HOME is unset before exporting again, so my new entry in ~/.zshrc
has now become
unset JAVA_HOME;export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_241`
Upon terminal relaunch, my previously failing gradlew
commands now function as before.
To me this feels like a better solution as I've not removed any libs and I have only affected java home from my own terminal commands. It's a shame that I need to specify the precise version as this will break at some point in the future.
Solution 4:[4]
on BIG SUR people who get this error have probably got a custom java installation. Remove it with the following
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Oracle/Java
after that unset any custom JAVA_HOME you have and remove it from your shell and it should start working again.
Solution 5:[5]
I got the exact same problem. I solved it by installing OpenJDK 8 JDK
. My machine is running centos
so here is my installing command
sudo yum install java-1.8.0-openjdk-devel
.
I learned from this article that there are two different Java packages, Java Runtime Environment (JRE) and Java Development Kit (JDK). JRE is for running Java programs, and JDK is for developing Java applications. I only had had JRE installed, but not JDK. After installing JDK, my build ran successfully
Solution 6:[6]
> Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
it's set to /usr/lib/jvm/java-8-openjdk-amd64/jre
.
Should set the JAVA_HOME to /usr/lib/jvm/java-8-openjdk-amd64/
If your OS is Ubuntu, make suer to install openjdk jdk by sudo apt-get install openjdk-8-jdk
sudo apt install openjdk-8-jre-headless
will install jre, not jdk
Solution 7:[7]
From the data provided, It is sure that java
is in the environment path. But, It doesn't confirm that JAVA_HOME is set to a JDK directory. Are you sure JAVA_HOME
is not set to /usr/lib/jvm/java-8-openjdk-amd64/jre
instead of /usr/lib/jvm/java-8-openjdk-amd64
or /usr/lib/jvm/default-java
?
Because, If JAVA_HOME
is set, then gradlew will ignore java
binary in the PATH and execute $JAVA_HOME/bin/java
which in turn will be available in System.getProperty("java.home")
which is logged in this exception ( see jarSearchingUtil.Kt )
Otherwise, You can try declaring JAVA_HOME directly in the gradlew file
Solution 8:[8]
On windows, add this to gradle.properties, with your jdk version
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_102
Solution 9:[9]
Things were all working fine before update to Mac Big Sur, I was using Jenkins on my local machine with Fastlane 'sh Fastlane beta' for firebase distribution. It was a flutter project.
I just added org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
in gradle.properties. And this fixed my issue.
Solution 10:[10]
I solved the problem by deleting a kind of version of java.
I had 2 kinds of Java, as below picture.
But I got a failure when I was executing ./gradlew clean assembleRelease
, it's remind me maybe the problem is about which JDK I used.
Then, I find the content of 2 kinds of java's home were different with each other. The left is which one I download from Oracle.
So, I tried to fix it by deleting the first java's home.(Compress the folder for copy at first).
It's work!
Solution 11:[11]
first
follow @Tom Aranda solution
https://stackoverflow.com/a/65132651/1367344
but didn't remove ./gradle
folder
second
if gradle faild :
./gradlew clean build --refresh-dependencies
to force Gradle to update dependencies
found this comment in this question : https://stackoverflow.com/a/48438866/1367344
Solution 12:[12]
If you are using a Mac, the trick is to install the JDK from Oracle, they are now changing license policies so apparently it isn't totally free anymore for commercial use. That said, once you install, you find the JDK on the MAC at : "/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home" if you go to gradle.properties, you can insert the line : "org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home" into the file. Restart Android studio, select the Android device, and it should work. Interestingly enough if you go to Finder, and navigate to the folder, then drag the folder into the gradle.properties file in textedit or vim, the path just shows up magically. I've been using Macs for over 10 years and only found that during this new endeavor into Android Studio. It did for me. Thanks to Stack Overflow community, it is a essential part of any application developer's toolkit.
Solution 13:[13]
1.Install Java
https://www.oracle.com/java/technologies/downloads/
2. find java path
/usr/libexec/java_home -V
3. set mac envirment
vim ~/.bash_profile
edit profile:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
export CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH:
source ~/.bash_profile
4. verify
@B-X24EQ05P-1937 jdk1.8.0_321.jdk % java -version
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
Solution 14:[14]
Was facing this issue in open jdk 8, switching to open jdk 11 solved it for me.
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/"
Solution 15:[15]
It was giving me error FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:compileDebugKotlin'. > Kotlin could not find the required JDK tools in the Java installation 'C:\Program Files\Java\jre1.8.0_281' used by Gradle. Make sure Gradle is running on a JDK, not JRE
I solved it by downloading and install Java SE Development Kit 8 and after installed folder has been created in path C:\Program Files\Java\jdk1.8.0_281
Solution 16:[16]
In my case, my lab has windows 7 and visual studio and android studio and flutter environment. When i Ran start debugging, same problem was happened.
To solve this problem,
First, Install Java Extension Pack by use extensions on visual studio.
Second, Follow Java Extension Pack, it required JDK 11 on config running screen.
Third, Download and install JDK(java develop kit) 11
Forth, When you install, you have to do check Path set on installation process. Maybe, it is not set Path automatically. you must check making path.
If you set and install correctly, It is appeared automatically at System environment variable as JAVA_HOME name. not user variable.
Run again main dart. you can see emulator correctly
Solution 17:[17]
On ubuntu 20.04, This works for me:
sudo apt install default-jdk
Solution 18:[18]
I struggled alot with this. (MAC OS Monterey)
But what works for me now is
- Installing the JDK 8 from Oracle's website. (Login was required)
- Add
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_331.jdk/Contents/Home
in the gradle.properties (jdk1.8.0_331.jdk was the name of my jdk folder, if you have another version you will have to use your own version / folder name there.) - I created a file called local.properties in the root of android folder in your project. There i added the line
sdk.dir = /Users/USERNAME/Library/Android/sdk
USERNAME should be your mac's username.
I tried declaring it as a home variable in the terminal but for some reason it wouldn't work. But telling the gradle.properties in step 2 worked it out :)
Solution 19:[19]
A simple restart on my computer and it worked again
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow