Unsupported class file major version 61 error

I am trying to run a flutter app, and this error appeared while trying to, what I did was that I wanted to run flutter apps without android studio, so I download android SDK and JDK 17, after I ran flutter doctor and it gave me that everything is good, I tried to run and it gave me this error:

FAILURE: Build failed with an exception. * Where: Build file 'E:\Flutter Apps\first_app\android\build.gradle' * What went wrong: Could not compile build file 'E:\Flutter Apps\first_app\android\build.gradle'. > startup failed: General error during semantic analysis: Unsupported class file major version 61 ............. 

So I tried an older version of JDK, it gave me another error, so I saw a third solution to run with JDK 17, which is to downgrade the gradle in gradle.properties, but it just gave me a fourth error, so does anyone know a final solution for this error ??

8

3 Answers

Based on the answer of DeveloperOmar 100 I found the following solution:

  1. switch your Java version to a compatible version, in my case to Java version 16.0.2

    To switch it you have to set your PATH. (e.g for Mac, you can use the java_home command).

  2. check your Gradle version and update that one too, so it is compatible (see the Gradle wrapper docs) so in my case I had to change the distributionUrl property in android/gradle/wrapper/gradle-wrapper.properties:

    distributionUrl=https\:// 
3

I ran into the same problem when I tried out Kotlin/Compose on my windows computer. I followed the instructions at

I struggled with this for a few hours before I finally was able to solve all the problems I encountered.

Solution

  • In gradle settings changed Gradle JVM: 11 (version 11.0.12)

  • In build.gradle.kts I deleted

    tasks.withType { kotlinOptions.jvmTarget = "16" }

What caused the problems

I started by installing

  • latest JDK (version 17)
  • IntelliJ IDEA 2021.3.2 (Community Edition)

Then I created a 'hello world' example with following settings:

  • Project template: Compose Desktop Application uses Kotlin 1.5.31

  • Build system: Gradle Kotlin

  • Project JDK: 17 Oracle OpenJDK version 17.0.2

  • Template: Compose Desktop Module

  • Target JVM version: 16

  • Test framework: JUnit 5

When the project was created I updated build.gradle.kts

plugins { kotlin("jvm") version "1.6.10" id("org.jetbrains.compose") version "1.0.1" } 

First error at build

BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 61

I fixed this by changing gradle settings

  • Gradle JVM: 11 (version 11.0.12)

Now the build was ok but run would fail

Second error at run

Execution failed for task ':run'. Process 'command 'C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin\java.exe'' finished with non-zero exit value 1

This was solved by deleting

tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "16" } 

in build.gradle.kts

Simply remove java 17 from the system. Thats helped me

7

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like