React Native: 'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target incompatibility
Matthew C.
—When using Expo or Android Studio IDE to build a React Native Android application, you get the following error:
FAILURE: Build failed with an exception. Task :react-native-gradle-plugin:compileKotlin 'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target
The problem occurs when the React Native Gradle plugin’s Java Virtual Machine (JVM) target compatibility check fails due to the use of inconsistent Java bytecode versions.
Ensure the same Java version is used across your project:
If you have multiple Java versions installed on your computer, including Java 11, ensure your JAVA_HOME
environment variable points to the correct version.
If you’re using Windows, open the Command Prompt and run it as an administrator so you can add a system environment variable. Set the value of the JAVA_HOME
environment variable to your JDK (or JRE) installation path:
setx /m JAVA_HOME "C:\Program Files\Java\jdk11.0.17.8"
If you’re using macOS, set the JAVA_HOME
environment variable by adding the following line to your shell’s configuration file:
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
~/.zshrc
or ~/.zprofile
.~/.bash_profile
or ~/.bashrc
.React Native recommends you use the Homebrew package manager to install the version 11, Azul Zulu build of OpenJDK on macOS and use the popular Chocolatey package manager to install JDK version 11 on Windows.
Note: If you are using the latest version of React Native, version 0.75, React Native recommends you install JDK version 17, update the React Native version in your project, and update Android Studio if possible.
If you are using Expo Application Services (EAS), you can specify a build image that includes JDK 11 in your eas.json
file:
{ "build": { "development": { "image": "ubuntu-22.04-jdk-11-ndk-r21e" } } }
If you are using Android Studio, you may get the following error after installing or setting your JDK version to JDK 11:
FAILURE: Build failed with an exception. Could not determine dependencies of task ':app:compileDebugJavaWithJavac'.
Fix this error by updating the Gradle JDK version:
The JDK contains everything you need to develop and run Java apps, including the JVM and tools for building your app. The JVM is an interpreter that executes Java applications.
React Native Android projects use both Java and Kotlin code:
Gradle is a Java build tool used to compile Android apps; it needs to compile the Kotlin and Java code to compatible bytecode versions.
The initial error indicates that the project is trying to compile Java code targeting Java version 1.8 and Kotlin code targeting Java version 11, which Gradle doesn’t allow. Gradle requires consistent Java bytecode versions across your project.
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.