57

I got this on my android part of Flutter.

Unsupported Java. 
Your build is currently configured to use Java 17.0.2 and Gradle 7.0.2.

Possible solution:
 - Open Gradle wrapper settings, change `distributionUrl` property to use compatible Gradle version and reload the project

Please kindly tell the solution to this. I would really appreciate your answer.

Punreach Rany
  • 2,560
  • 7
  • 23
  • 56

10 Answers10

49

After Updating Android studio I have faced this issue.

You Can Simply Follow These steps:

Open Your Android Studio Project

Go To Gradle Scripts -> gradle-wrapper.properties

My old setting like this

My old setting like this

Now You Can Change distributions/Gradle versions 7.2 To 7.6 7.2 To 7.6 like this

it's working for me .

You can also use 7.4 + version . it's also working for me.

Ronik Limbani
  • 667
  • 4
  • 5
37

Gradle 7.0.2 support java version 16, in your project Java is setted for version 17, so solution is to upgrade gradle version or downgrade Java version.

Dharman
  • 30,962
  • 25
  • 85
  • 135
ivanX
  • 489
  • 4
  • 4
  • 1
    If you're using Android Studio, in gradle-wrapper.properties you can change distribution URL from 7.0.x to 7.4.1 – claudiodfc Mar 18 '22 at 14:14
17

Go to file > project structure > SDK location > Gradle settings There choose Embedded jdk. This will resolve the issue.

Akash Dev
  • 179
  • 1
  • 2
14

Every answer they give different java version or different gradle version.

To avoid this confusion, I listed Java/Gradle compatibility table. https://docs.gradle.org/current/userguide/compatibility.html

Example: If your gradle version 7.5, you should set java version 18

enter image description here

How to change Java version?

Settings -> Build,Execution,Deployment -> Build tools -> gradle -> Gradle jdk -> choose Java version based on your gradle version.

Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159
10

You can resolve this by changing the Gradle version on gradle-wrapper.properties file and the JDK version from the project structure.

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
3

Steps

  • Navigate to the root of your project. In my own case -/flutterProject/
  • Locate and goto gradle/wrappper folder, Where you will find gradle-wrapper.properties file.
  • there you will change the distributionUrl to the new version
    Ex: distributionUrl=https://services.gradle.org/distributions/gradle-7.2-bin.zip
eclat_soft
  • 602
  • 7
  • 9
3

The problem is the latest version of the Android Studio(Pelican). To fix the problem I modified this:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

And in the build.gradle(ANDROID):

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.2' //THIS VERSION WORKS!!!
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
Leandro Ariel
  • 727
  • 8
  • 5
2

Gradle 7.5 not supports java version 19, so the solution is to upgrade gradle version or downgrade Java version.

in my case I'm upgrade the gradle version as showing below

  1. Click on setting at right side end and click on "Project Structure"
  1. Change the Gradle version to 7.6 and then click and apply
  1. Goto Build option and click on "clean" project and "rebuild project"
Anonymous
  • 835
  • 1
  • 5
  • 21
1

Java/Gradle versions compatibility matrix can be found here:

It can be seen that Java 17 is not compatible with Gradle 7.0. In case you want to keep the Gradle version, you can downgrade Java to version 16 by the next steps in Android Studio:

  • File
  • Project Structure...
  • SDK Location
  • Gradle Settings
  • Gradle JDK
  • Download JDK...
  • Set version to 16 and click Download
0

Try to change Java version to Java 11 and try again. it works for me.

BugsCreator
  • 433
  • 3
  • 10