ssshan
ssshan

Reputation: 101

React Native: 'compileJava' task(current target is 1.8) and 'compileKotlin' task(current target is 11) jvm target compatibility problem

I am new to the React Native development with using Mac M1. When I was running React Native Android, I got the errors below.

I really have no idea how to fix this error, Appreciate if anyone could help, thanks again!

> Task :react-native-gradle-plugin:compileKotlin
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.

> Task :react-native-gradle-plugin:compileKotlin FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8/userguide/command_line_interface.html#sec:command_line_warnings
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt: (28, 33): Unresolved reference: replaceFirstChar
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt: (28, 52): Unresolved reference: it
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt: (252, 16): Unresolved reference: lowercase
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/Os.kt: (13, 38): Unresolved reference: lowercase
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/Os.kt: (15, 57): Unresolved reference: lowercase
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/Os.kt: (18, 54): Unresolved reference: lowercase
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/Os.kt: (19, 52): Unresolved reference: lowercase
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt: (190, 27): Type mismatch: inferred type is Unit but CharSequence was expected
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt: (190, 44): Unresolved reference: replaceFirstChar
e: /Users/fuzhonghan/Documents/AwesomeAndroidProject/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt: (190, 63): Unresolved reference: it

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Compilation error. See log for more details

command line javac --version result...

javac 11.0.15

command line java --version result...

openjdk 11.0.15 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

And contents of gradle-wrapper.properties are below... (I've downgraded gradle version from 7.1.1 to 6.8 due to plugin maven was removed from gradle 7.)

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

Upvotes: 5

Views: 6661

Answers (1)

Elyse Segebart
Elyse Segebart

Reputation: 41

I resolved my Gradle Plugin error from this StackOverflow answer: Update OpenJDK 11

I updated my JDK using chocolatey in PowerShell with admin privileges by typing:

choco install -y openjdk11

And then I updated my Gradle version in project/android/app/build.gradle from 6.9 to 7.4.2.

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

I recently upgraded my React Native to 69.1 and so I investigated what version of Gradle needed to be used. I found this documentation.

React Native Gradle Prerequisites

Android prerequisites were

  1. Using Gradle 7.x and Android Gradle Plugin 7.x
  2. Using the new React Gradle Plugin
  3. Building react-native from Source

Next, in project build.gradle I changed the build tools to classpath("com.android.tools.build:gradle:7.2.1").

I updated to the latest version of Android Studio 2021.1.1 or newer.

I no longer have the compileKotlin and compileJava error.

Upvotes: 1

Related Questions