androidreact-nativekotlingradleandroid-gradle-plugin

"Execution failed for task ':react-native-gradle-plugin:compileKotlin'" ,when upgraded from 0.72.5 to 0.74.2


The class is loaded from C:/Users/USER/.gradle/wrapper/dists/gradle-8.6-all/3mbtmo166bl6vumsh5k2lkq5h/gradle-8.6/lib/kotlin-stdlib-1.9.20.jar!/kotlin/collections/CollectionsKt__CollectionsKt.class

e: C:\\Users\\USER\\Downloads\\picky_anu_anshif\\picky_anu_anshif\\node_modules\\react-native-gradle-plugin\\src\\main\\kotlin\\com\\facebook\\react\\utils\\ProjectUtils.kt: (51, 48): Class 'kotlin.text.StringsKt__StringsKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.

The class is loaded from C:/Users/USER/.gradle/wrapper/dists/gradle-8.6-all/3mbtmo166bl6vumsh5k2lkq5h/gradle-8.6/lib/kotlin-stdlib-1.9.20.jar!/kotlin/collections/ArraysKt___ArraysKt.class

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.

My files are:
android/build.gradle:

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 26
        compileSdkVersion = 34
        targetSdkVersion = 34

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "26.1.10909125"

        kotlin_version = '1.9.22'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.15'
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:perf-plugin:1.4.2'
    }
}

android\gradle\wrapper\gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

package.json:

{
  "name": "Picky_Assist",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.23.1",
    "@react-native-community/cli-platform-ios": "^11.3.5",
    "@react-native-community/netinfo": "^9.4.1",
    "@react-native-community/progress-view": "^1.4.1",
    "@react-native-community/push-notification-ios": "^1.11.0",
    "@react-native-cookies/cookies": "^6.2.1",
    "@react-native-firebase/app": "^16.5.1",
    "@react-native-firebase/messaging": "^16.5.1",
    "@react-navigation/drawer": "^6.5.7",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "@reduxjs/toolkit": "^1.9.5",
    "axios": "^1.2.3",
    "crypto-js": "^4.1.1",
    "deprecated-react-native-prop-types": "^4.2.3",
    "package": "^1.0.1",
    "react": "18.2.0",
    "react-native": "0.74.2",
    "react-native-base64": "^0.2.1",
    "react-native-camera": "^4.2.1",
    "react-native-date-picker": "^4.3.3",
    "react-native-device-info": "^10.7.0",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.16.2",
    "react-native-gradle-plugin": "^0.71.19",
    "react-native-linear-gradient": "^2.7.3",
    "react-native-permissions": "^3.10.1",
    "react-native-push-notification": "^8.1.1",
    "react-native-qrcode-scanner": "^1.5.5",
    "react-native-reanimated": "^3.4.1",
    "react-native-restart": "^0.0.27",
    "react-native-safe-area-context": "^4.6.4",
    "react-native-screens": "^3.22.1",
    "react-native-simple-toast": "^3.3.1",
    "react-native-snackbar": "^2.6.2",
    "react-native-splash-screen": "^3.3.0",
    "react-native-toast-message": "^2.2.0",
    "react-native-webview": "^11.26.1",
    "react-redux": "^8.1.1",
    "redux": "^4.2.1",
    "redux-persist": "^6.0.0",
    "toggle-switch-react-native": "^3.3.0"
  },
  "reactNativePermissionsIOS": [
    "Camera",
    "MediaLibrary",
    "Microphone",
    "Notifications",
    "PhotoLibrary",
    "PhotoLibraryAddOnly"
  ],
  "devDependencies": {
    "@babel/core": "^7.24.7",
    "@babel/preset-env": "^7.24.7",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.74.84",
    "@react-native/eslint-config": "^0.74.84",
    "@react-native/metro-config": "^0.74.84",
    "@react-native/typescript-config": "0.74.84",
    "@types/crypto-js": "^4.1.1",
    "@types/metro-config": "^0.76.3",
    "@types/react": "^18.3.3",
    "@types/react-native-push-notification": "^8.1.1",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "^2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "yarn@3.6.4",
  "resolutions": {
    "react-native-permissions": "^3.8.0"
  },
  "overrides": {
    "react-native-qrcode-scanner": {
      "react-native-permissions": "^3.8.0"
    }
  }
}

MY versions:

C:\\Users\\USER\>java --version

java 17.0.10 2024-01-16 LTS

Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)

Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)

C:\\Users\\USER\>node -v

v20.15.0

Project was working fine when using 7.5.1; but, after updating to 8.6, this error message appeared.


Solution

  • upgrading @react-native/gradle-plugin solves the issue as well, no need to downgrade gradle.

    So the final configuration:

    gradle-wrapper.properties:

    distributionUrl=https://services.gradle.org/distributions/gradle-8.3-all.zip

    Note : Here you check which gradle is suitable for you. gradle-8.3 this works for me.