Task :react-native-gradle-plugin:compileKotlin FAILED, 'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11)
Asked Answered
P

12

18
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 936 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...

> Task :react-native-gradle-plugin:compileKotlin FAILED
'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.
1 actionable task: 1 executed

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
   > Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
   > Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s

    at makeError (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\execa\index.js:174:9)
    at C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\execa\index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runOnAllDevices (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
    at async Command.handleAction (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details

I have seen solutions which involve changing the classpath() and distribution URL, but I have already done it.

from my build.gradle file:

dependencies {
        classpath("com.android.tools.build:gradle:7.2.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:4.1.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

from gradle-wrapper

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

None of this fixes the error, additionally, i have noticed that running gradlew clean also provokes the same error

> Task :react-native-gradle-plugin:compileKotlin FAILED
'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.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
   > Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
1 actionable task: 1 executed

I have also tried adding the following piece of code to the build.gradle file

android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

kindly help me fix this, I used to use EXPO CLI previously and everything was working well, All of this happened in an attempt to learn the React-native CLI.

Probity answered 19/9, 2022 at 4:33 Comment(1)
Simply you need to install kotlin on Android Studio and do Gradle Sync again.Fiver
D
17

I had the same problem and to solve this problem I changed in gradle-wrapper.properties file

before:

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

after:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
Dian answered 2/2, 2023 at 12:23 Comment(2)
This only applies to react-native 0.70+Bonner
This fixed it for me when upgrading to Expo 48. Thanks!Td
P
4

I changed gradle version and solved it. Reference

//before
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip

//after
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
Pga answered 5/12, 2022 at 4:57 Comment(0)
F
2

I am facing the same issue where All Java packages were installed or synced perfectly but kotlin packages were not synced it throws an error of kotlin compilation.

I install kotlin package on Android Studio by following This.

Android Studio → Preferences… →Plugins → Browse Repository → type “Kotlin” in search box → install

After that, you need to remove the cache of this project from

File -> Invalidate caches -> Invalidate and Restart.

After that when your project is re-open and synced successfully then clean your project from Build -> Clean Project.

After that, all packages of kotlin were installed perfectly.

Fiver answered 19/9, 2022 at 6:10 Comment(1)
Hi thank you for the response, but I already have kotlin plugin installed. Also when I open the project on android studio, I'm unable to gradle sync it. Isn't the issue related to changing the java version from 1.8 to 11?Probity
S
1

I just installed jdk11 then run cd ./android/ && ./gradlew clean That works for me

We have to take care Gradle compatibility version with java version for react-native or flutter both framework. You can take a look for checking compatible version in mentioned url https://docs.gradle.org/current/userguide/compatibility.html

Shirr answered 24/1, 2023 at 22:21 Comment(0)
H
1
  1. cd android --> ./gradlew clean
  2. ./gradlew build
  3. cd ..
  4. npx react-native run-android

Its working fine...

Heligoland answered 4/4, 2024 at 11:32 Comment(0)
D
0

I hade the same issue using expo

I removed the eas.json file, as eas build creates a new eas.json file

It worked for me.

Delldella answered 24/3, 2023 at 10:21 Comment(0)
S
0

I had the same problem and to solve this problem I did:

  1. Installed java 11 and uninstalled that java 8;
  2. In package.json I prefixed the version with ^, then yarn install. (Update react native version 0.68.2 for ^0.68.2)

Reference: https://github.com/facebook/react-native/issues/34410

Smoothshaven answered 1/4, 2023 at 16:32 Comment(0)
V
0

This worked for me when I had the same issues:

rm -rf ./node_modules
yarn
npm run android

Deleted the node_modules and reinstalled. I think the issue could also be because I had used Android Studio to install the Gradle. Also check incase you have multiple versions of Java JDK installed, check to be sure of which one is being used by React Native.

Variate answered 1/2, 2024 at 15:32 Comment(0)
I
0

I had the same problem in react-native project and to solve this problem I comment this org.gradle.java.home=/Library/Java/..., in gradle.properties file.

https://i.sstatic.net/Wdxm6.png

goto android folder and run

  • ./gradlew clean
  • ./gradlew build

back to folder project run

  • npx react-native run-android

node v14.21.3 (npm v6.14.18), react: 17.0.2, react-native: 0.68.2, jdk-17, gradle-7.4-all.zip

Iceskate answered 3/2, 2024 at 3:19 Comment(0)
T
0

I solved this problem by running expo-doctor:

npx expo-doctor

and install it then it adjust the dependencies according to your sdk version, this solved my error

Toxicosis answered 27/2, 2024 at 9:21 Comment(0)
C
-1

info Opening app on Android... info A dev server is already running for this project on port 8081. info Installing the app...

Task :gradle-plugin:compileKotlin UP-TO-DATE Task :gradle-plugin:compileJava NO-SOURCE Task :gradle-plugin:pluginDescriptors UP-TO-DATE Task :gradle-plugin:processResources UP-TO-DATE Task :gradle-plugin:classes UP-TO-DATE Task :gradle-plugin:jar UP-TO-DATE Task :gradle-plugin:inspectClassesForKotlinIC UP-TO-DATE

Configure project :react-native-reanimated Android gradle plugin: 8.1.1 Gradle: 8.3 Observed package id 'platforms;android-33' in inconsistent location 'C:\Users\zahid\AppData\Local\Android\Sdk\platforms\android-33-3' (Expected 'C:\Users\zahid\AppData\Local\Android\Sdk\platforms\android-33') Warning: Observed package id 'platforms;android-33' in inconsistent location 'C:\Users\zahid\AppData\Local\Android\Sdk\platforms\android-33-3' (Expected 'C:\Users\zahid\AppData\Local\Android\Sdk\platforms\android-33') Warning: Observed package id 'platforms;android-33' in inconsistent location 'C:\Users\zahid\AppData\Local\Android\Sdk\platforms\android-33-3' (Expected 'C:\Users\zahid\AppData\Local\Android\Sdk\platforms\android-33') Checking the license for package NDK (Side by side) 25.1.8937393 in C:\Users\zahid\AppData\Local\Android\Sdk\licenses License for package NDK (Side by side) 25.1.8937393 accepted. Preparing "Install NDK (Side by side) 25.1.8937393 v.25.1.8937393".

Cynthea answered 16/3, 2024 at 20:3 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Melicent
P
-4

Found the solution, not sure why it works though

i used the following commands to start the build

npm start

now open another terminal and execute the following

npm run android

instead of

npx react-native start

and

npx react-native run-android

where the latter is suggested by the official documentation

Probity answered 19/9, 2022 at 17:54 Comment(1)
it even not related to question, it just a command to run react native appColourable

© 2022 - 2025 — McMap. All rights reserved.