Skip to content

Fixing "Could not open settings generic class cache" Gradle Error

Problem Statement

The "Could not open settings generic class cache" error occurs when building Android projects in Flutter, React Native, or standard Android development. This error typically appears with the message:

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

This error indicates a Java version compatibility issue between your installed JDK, Android Studio's bundled Java runtime, and your project's Gradle version.

Root Cause

The error occurs due to version mismatches in three key components:

  1. Java Development Kit (JDK) installed on your system
  2. Android Studio's bundled Java runtime (jbr folder in newer versions)
  3. Gradle version specified in your project

When these components have incompatible versions, Gradle cannot properly compile and cache the project settings, resulting in the class cache error.

Solutions

First, identify your current Java version:

bash
java -version

Check the compatibility between your Java version and Gradle using this table:

Java VersionMinimum Gradle Version
82.0+
94.3+
104.7+
115.0+
125.4+
136.0+
146.3+
156.7+
167.0+
177.3+
187.5+
197.6+
208.1+
218.4+

WARNING

Android development currently works best with Java 11 or 17. Higher versions may cause compatibility issues with some Android tooling.

Method 2: Configure Android Studio's Java Home

If your system has multiple Java versions, configure Android Studio to use a compatible version:

  1. Locate your Android Studio installation directory
  2. Find the jbr folder (Java runtime bundled with Android Studio)
  3. Set the JAVA_HOME environment variable to point to this directory:
bash
# Windows
JAVA_HOME=C:\Program Files\Android\Android Studio\jbr

# macOS/Linux
JAVA_HOME=/Applications/Android Studio.app/Contents/jbr

Method 3: Specify Java Home in Gradle Properties

Add this line to your android/gradle.properties file:

properties
org.gradle.java.home=C:/Program Files/Java/jdk-17

Replace the path with your actual JDK installation directory.

Method 4: Update Gradle Version

If your Java version is higher than your Gradle version supports, update your Gradle wrapper:

  1. Open android/gradle/wrapper/gradle-wrapper.properties
  2. Update the distribution URL to a compatible version:
properties
# For Java 17 compatibility
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
  1. Update the Gradle plugin in android/build.gradle:
gradle
dependencies {
    classpath "com.android.tools.build:gradle:7.2.0"
}

Method 5: Sync Project with Gradle Files in Android Studio

Sometimes, simply opening the Android module in Android Studio can resolve the issue:

  1. Open Android Studio
  2. Select File > Open and navigate to your project's android folder
  3. Wait for Gradle to sync and download dependencies
  4. Select Build > Rebuild Project
  5. Try running your Flutter/React Native command again

Step-by-Step Troubleshooting Guide

Follow these steps to systematically resolve the issue:

  1. Check Java version with java -version
  2. Verify Android Studio Java runtime by examining the release file in the jbr directory
  3. Ensure Gradle compatibility with your Java version using the compatibility table
  4. Update environment variables to point to compatible Java versions
  5. Clean your project with flutter clean or ./gradlew clean
  6. Rebuild your project

TIP

For Flutter projects, running flutter doctor can help identify configuration issues with your Android toolchain.

Prevention

To avoid this issue in the future:

  • Use Java 11 or 17 for Android development
  • Keep Android Studio and its components updated
  • Regularly check Gradle and Java compatibility when updating either
  • Consider using JDK version managers for switching between Java versions
Create Java version switching aliases (Linux/macOS)
bash
# Add to your .bashrc or .zshrc
alias changeJavaTo8='sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/bin/java'
alias changeJavaTo11='sudo update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java'
alias changeJavaTo17='sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java'

Conclusion

The "Could not open settings generic class cache" error is ultimately a compatibility issue that can be resolved by ensuring your Java version, Android Studio's runtime, and Gradle version are all aligned. The most reliable approach is to use Java 11 or 17 with a compatible Gradle version, as these are well-supported by Android's build tools.

By following the methods outlined above, you should be able to resolve this build error and continue with your Android development workflow.