react-native: Failed to apply plugin 'com.facebook.react'

Description

After I upgraded the react native to 0.73.0-rc.4 it started giving this error

Failed to apply plugin ‘com.facebook.react’.> The value for property ‘languageVersion’ is final and cannot be changed any further.

React Native Version

0.73.0-rc.4

Output of npx react-native info

System: OS: macOS 14.1.1 CPU: (12) arm64 Apple M2 Max Memory: 82.88 MB / 32.00 GB Shell: version: “5.9” path: /bin/zsh Binaries: Node: version: 18.18.0 path: ~/.nvm/versions/node/v18.18.0/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 9.8.1 path: ~/.nvm/versions/node/v18.18.0/bin/npm Watchman: version: 2023.10.02.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.13.0 path: /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: - DriverKit 23.0 - iOS 17.0 - macOS 14.0 - tvOS 17.0 - watchOS 10.0 Android SDK: API Levels: - “23” - “29” - “30” - “31” - “32” - “33” - “34” Build Tools: - 29.0.2 - 30.0.2 - 30.0.3 - 31.0.0 - 33.0.0 - 33.0.1 - 33.0.2 - 34.0.0 System Images: - android-30 | Google APIs ARM 64 v8a - android-31 | Google Play ARM 64 v8a - android-32 | Automotive with Play Store ARM 64 v8a - android-33-ext4 | Google Play ARM 64 v8a - android-33 | Android Automotive with Google APIs ARM 64 v8a - android-34 | Google APIs ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2022.3 AI-223.8836.35.2231.10811636 Xcode: version: 15.0.1/15A507 path: /usr/bin/xcodebuild Languages: Java: version: 17.0.9 path: /usr/bin/javac Ruby: version: 2.6.10 path: /usr/bin/ruby npmPackages: “@react-native-community/cli”: Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.73.0-rc.4 wanted: 0.73.0-rc.4 react-native-macos: Not Found npmGlobalPackages: “react-native”: Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: true newArchEnabled: false

Steps to reproduce

fails at android sync

Snack, screenshot, or link to a repository

Screenshot_2023-11-21_at_5_36_43 PM

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

We are running into this also when upgrading to RN 0.73.0 - would love to know how this was resolved for you.

Hey @C2418M31, 2 days ago I stumbled upon the same error. The explanation is the following, the new Gradle Version throws this error when there are updates on languageVersion, which is set through this configs in the gradle:

android {
 compileOptions {
            sourceCompatibility JavaVersion.VERSION_[any version]
            targetCompatibility JavaVersion.VERSION_[any version]
        }

        kotlinOptions {
            jvmTarget = "[kotlin_version]"
        }
}

It’s because the new React Native version has already the base version set, you can check this out in your project node module folder: node_modules/@react-native/gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt.

You have two ways to solve it, chose one of them:

  1. Patch the React Native gradle configs by commenting out the lines setting the version
internal object JdkConfiguratorUtils {

  fun configureJavaToolChains(input: Project) {
    // Check at the app level if react.internal.disableJavaVersionAlignment is set.
    if (input.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
      return
    }
    input.rootProject.allprojects { project ->
      // Allows every single module to set react.internal.disableJavaVersionAlignment also.
      if (project.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
        return@allprojects
      }
      val action =
          Action<AppliedPlugin> {
            /*project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext
              ->
              ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
              ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17
            }*/ -> these lines out
          }
      project.pluginManager.withPlugin("com.android.application", action)
      project.pluginManager.withPlugin("com.android.library", action)
      project.pluginManager.withPlugin("org.jetbrains.kotlin.android") {
        // project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17) -> this line out
      }
      project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
       // project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17) -> this line out
      }
    }
  }
}
``` (not recommended)
2. Remove these declarations for version update from your gradle file.
3. Use a different Gradle Version that does not throw this error, check here with version does not do that https://docs.gradle.org/current/userguide/upgrading_version_8.html

@harrymash2006 could you shed me some light which module caused this error? I simply upgraded react-native from 0.72.5 to 0.73.1 and started getting this error