Gradle build failed - incompatible classes were found in dependencies

I’ve been trying to upgrade my project’s gradle from v7.3.3 to v8.0.2, and in the process I’ve been seeing the following error as I attempt to clean the project:

/Users/johndoe/.gradle/caches/8.0.2/generated-gradle-jars/gradle-api-8.0.2.jar!/META-INF/configuration-cache.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

It’s clear to me that I needed to bump the Kotlin version from 1.6.0 to 1.8.0 for gradle v8.0.2. So I’ve went ahead and cleared that specific cache to see if it’s a cache-related issue, but to no avail. I’m also seeing the same issue appear when trying to run gradle wrapper --gradle-version 8.0.2 --stack-trace Some key datapoints:

  • Running Android Studio Electric Eel (Kotlin 1.8.0-compatible)
  • Kotlin 1.8.0 is downloaded, and I’ve included kotlinVersion = "1.8.0" in my build.gradle, under buildscript and ext (I’ve tried both kotlinVersion = "1.8.0" and kotlin_version = "1.8.0" - hasn’t made a difference.
  • This is React Native project. Currently running version 0.68.2.
    Below is my build.gradle at the project level:
import org.apache.tools.ant.taskdefs.condition.Os

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        googlePlayServicesAuthVersion = "19.2.0"
        kotlin_version = '1.8.10'

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
    }
    repositories {
        google()
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
    }
    dependencies {
        classpath('com.android.tools.build:gradle:7.4.2')
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath'com.google.gms:google-services:4.3.10'
        classpath("de.undercouch:gradle-download-task:4.1.2")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        google()
        // This is needed or else react-native-video will error out
        jcenter() {
            content {
                includeModule("com.yqritc", "android-scalablevideoview")
            }
        }
        maven { url 'https://www.jitpack.io' }
    }
}

I understand this is a pretty widely reported issue, but it looks pretty diverse in nature. None of the previous solutions have solved the issue. I’d be more than happy to provide extra details if need be. Thanks for your time.

Figured it out. I needed to update my distributionUrl in my android/gradle/wrapper/gradle-wrapper.properties to distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip and proceed from there. We’re good. Thanks for your time.