skip to Main Content

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.0'

        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.

2

Answers


  1. Chosen as BEST ANSWER

    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, which is up from 7.4.2. I failed to understand that this represented the versioning of the Gradle Android Studio plugin instead of the actual Gradle version. We’re good. Thanks for your time.


  2. This issue can have many causes. I went through this as well and solved it for our project. I haven’t seen these online, so hopefully they are new solutions for you to try.

    In my case, one of our dependencies was using the kotlin-android-extensions plugin in its gradle file. That plugin has been deprecated and is incompatible with the newer version of Kotlin. I believe I found this by building the project in Android Studio, where the error messages are better.

    I was able to build our project after patching the library (Plaid) to remove that plugin. Sample patch below:

    diff --git a/node_modules/react-native-plaid-link-sdk/android/build.gradle b/node_modules/react-native-plaid-link-sdk/android/build.gradle
    index 5d583d8..34ae703 100644
    --- a/node_modules/react-native-plaid-link-sdk/android/build.gradle
    +++ b/node_modules/react-native-plaid-link-sdk/android/build.gradle
    @@ -27,7 +27,7 @@ buildscript {
     
     apply plugin: 'com.android.library'
     apply plugin: "kotlin-android"
    -apply plugin: "kotlin-android-extensions"
    +// apply plugin: "kotlin-android-extensions"
     
     android {
         compileSdkVersion 31
    

    We also had a library which used a non-exhaustive switch statement, which is a compile time error under Kotlin 1.8.0. In that case adding

      else -> null
    

    to the end of the switch statement fixed it.

    In general, since you have already bumped the version in your project’s build.gradle, the problem is almost certainly in one of your dependencies or native libraries. If neither of these is your issue, hopefully building in Android Studio is enough to find out what needs to be changed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search