7

I first created a new flutter project.

But I got this error:

* 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_261' used by Gradle. Make sure Gradle is running on a JDK, not JRE.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 33s
Exception: Gradle task assembleDebug failed with exit code 1

I also tried this method, but it didn't work.

enter image description here

5 Answers5

17

Step1:

I added the following line to the gradle.properties file

org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_261 your jdk version

Step2:

add the following line to gradle-wrapper.properties file

to the address => \flutter_app\android\gradle\wrapper\gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
Boken
  • 4,825
  • 10
  • 32
  • 42
Javad Dehban
  • 1,282
  • 3
  • 11
  • 24
5

I got this error when my JRE updated, but my JDK didn't. After I downloaded and installed the updated JDK, the error went away.

Here is a link to the JDK download: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

Scott
  • 371
  • 4
  • 8
0

One of these two methods should help you:

  1. In gradle.properties in the .gradle directory in your HOME_DIRECTORY set org.gradle.java.home=/path_to_jdk_directory

OR:

  1. In your build.gradle
compileJava.options.fork = true
compileJava.options.forkOptions.executable = '/path_to_javac'

answer taken from here

Robula
  • 649
  • 1
  • 12
  • 29
lQsdY8
  • 23
  • 2
  • 9
0

Simple solution to this what my issue resolved

  1. Just go to your project Android folder in flutter project
  2. Open gradle.properties File and add line ==> org.gradle.java.home=C:\Program Files\Java\jdk-13.0

C:\Program Files\Java\jdk-13.0 - This is Your JDK location in your PC Please check if JDK not installed then first install JDK and provide specific JDK location . Thanks

-2

upgrade java jdk then go to

file -> project structure -> project setting -> project change "project sdk"

to the latest JDK

Boken
  • 4,825
  • 10
  • 32
  • 42
Hossam
  • 1
  • 1