'I have problem with gradle in flutter. Could not open settings generic class cache for settings file

Here is the error:

FAILURE: Build failed with an exception.

  • What went wrong: Could not open settings generic class cache for settings file 'E:\proj\android\settings.gradle' (C:\Users\patel.gradle\caches\6.7\scripts\1fnwrr8g4rohfp291nvlxj5qe).

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

  • 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 2s Exception: Gradle task assembleDebug failed with exit code 1


I already change JDK 16 to 8 and update Gradle version.



Solution 1:[1]

I added this line to ./android/gradle.properties for OSX org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home Android Studio changed their file path for the jre so I think this will go away once flutter fixes with a new version

Solution 2:[2]

In gradle.properties, try to add that org.gradle.java.home=C:\\Program Files\\Android\\Android Studio\\jre

Solution 3:[3]

I added this line to ./android/gradle.properties for OSX:

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home

This is what worked for me.

Solution 4:[4]

To resolve this issue you have to follow these steps, they worked for me:

  1. Go to your gradle-wrapper.properties file and change the gradle plug-in version to the latest. e.g distributionUrl=https://services.gradle.org/distributions/gradle-7.2-bin.zip

It means 7.2 is the latest as at the time of writing this.

NOTE: Open your flutter app: android>gradle>wrapper>gradle-wrapper.properties

  1. Then, open your app and go to: android>build.gradle

open the file and in the buildScript and under the dependencies block, give a compactible version to the Gradle.

An example is shown below.

buildscript {
  ext.kotlin_version = '1.6.21'
  repositories {
      google()
      mavenCentral()
  }

  dependencies {
      classpath 'com.android.tools.build:gradle:7.1.3'
  }
}
  1. In your manifest file: android>app>src>main>androidManifest.xml

open it and under the activity tag, add: android:exported="true"

You can then invalidate caches and rebuild your project. try it and give me feedback.

Reference is from the official doc

https://developer.android.com/studio/releases/gradle-plugin

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Flamageil
Solution 3 Etienne Kaiser
Solution 4