skip to Main Content

Hello everyone I am trying to create and run a react native app. I run
npx react-native init rn4 but when I run npm run android I have this error:

> 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.
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactReactExtension.kt: (10, 37): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactReactExtension.kt: (119, 30): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactReactExtension.kt: (135, 26): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactReactExtension.kt: (155, 32): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactReactExtension.kt: (161, 31): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactReactExtension.kt: (169, 36): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactReactPlugin.kt: (99, 48): 'reactRoot: DirectoryProperty' is deprecated. reactRoot was confusing and has been replace with rootto point to your root project and reactNativeDir to point to the folder of the react-native NPM package
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactTaskConfiguration.kt: (10, 37): 'ApplicationVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactTaskConfiguration.kt: (11, 37): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactTaskConfiguration.kt: (12, 37): 'LibraryVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactTaskConfiguration.kt: (28, 51): 'BaseVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactTaskConfiguration.kt: (131, 12): 'ApplicationVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactTaskConfiguration.kt: (132, 12): 'LibraryVariant' is deprecated. Deprecated in Java
w: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainkotlincomfacebookreactTaskConfiguration.kt: (250, 14): 'BaseVariant' is deprecated. Deprecated in Java

> Task :react-native-gradle-plugin:compileJava
6 actionable tasks: 6 executed
Note: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainjavacomfacebookreactcodegengeneratorSchemaJsonParser.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* Where:
Build file 'C:UsersemanuApprn4androidappbuild.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

* 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 59s

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
Note: C:UsersemanuApprn4node_modulesreact-native-gradle-pluginsrcmainjavacomfacebookreactcodegengeneratorSchemaJsonParser.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* Where:
Build file 'C:UsersemanuApprn4androidappbuild.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

* 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 59s

    at makeError (C:UsersemanuApprn4node_modulesexecaindex.js:174:9)
    at C:UsersemanuApprn4node_modulesexecaindex.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:UsersemanuApprn4node_modules@react-native-communitycli-platform-androidbuildcommandsrunAndroidrunOnAllDevices.js:109:5)
    at async Command.handleAction (C:UsersemanuApprn4node_modules@react-native-communityclibuildindex.js:192:9)
info Run CLI with --verbose flag for more details.

I also run cd android && ./gradlew clean and the output is:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:UsersemanuApprn4androidappbuild.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

This is the file in android/gradle/wrapper/gradle-wrapper.properties

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

and this is the output when I run ./gradlew --version

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          1.8.0_302 (Oracle Corporation 25.302-b08)
OS:           Windows 10 10.0 amd64

I read similar posts but I haven’t been able to fix it. With folders that I created some days ago I have no problem when I run the app.

Someone can help me please?
Very thanks!

7

Answers


  1. Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.

    Ultimately you need a newer version of Java to run this. There are many resources online to assist you with this. As it is recommending Java 11 I would stick with that. One place to get Java 11 for Windows is on the Oracle downloads site (as you currently have the Oracle build) but there are others related to OpenJDK too.

    Login or Signup to reply.
  2. If you are using React Native witch Chocolatey, you must update JDK version to 11.
    In order to do the update, execute this in PowerShell (with admin privileges):

    choco install -y openjdk11
    

    After that, the first time (only the first time) you run npm android, you will get a lot of warnings, but the built of the project will work.

    If you continue receiving an error, maybe you need to adjust the gradle version of your project to be compatible with the new JDK version.
    You can achieve this by editing the file YOUR_PROJECTandroidgradlewrappergradle-wrapper.properties
    Update the version of distributionUrl to 7.4.2

    I hope I have been helpful

    Login or Signup to reply.
  3. I was having this very same problem here. I tried MouTio’s solution and updated the distributionUrl to 7.4.2 at Project-Nameandroidgradlewrappergradle-wrapper.properties but that still gave me this error here:

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

    ‘compileJava’ task (current target is 1.8) and ‘compileKotlin’ task (current target is 11) jvm targeta 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 ‘compilerRun
    Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilat

    However the error was fixed after running this choco install -y nodejs-lts openjdk11 with a command line using administration privileges.

    and don’t forget to run npm run android with a refreshed terminal.

    Login or Signup to reply.
  4. The message is gone at last.

    Before to that do the following [ iam using Mac]

    1. Have JDK11 installed and HOME set
    2. If you have any old version or have installed latest 18 and not as mentioned in the error. Then follow this URL to remove the the installation and ensure the path is set properly by following this [refer to the highest scored one]
    3. Now to set the path follow this URL. Written by Arv
    4. Now look for this file in android folder
      android/.idea/compiler.xml and change the target set as "1.8" to "11"
      enter image description here
    5. run ./gradlew clean [run it twice..else same message will be visible]
    Login or Signup to reply.
  5. 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.

    Solution

    Execute following commands

    • run cmd(Administrator) the past
      choco install -y openjdk11
    Login or Signup to reply.
  6. I just installed jdk11 then run cd ./android/ && ./gradlew clean That works for me

    Login or Signup to reply.
  7. openjdk11 v11.0.16.20220913 already installed.
    
    node js version: v18.14.0
    
    java version "19.0.2" 2023-01-17
    Java(TM) SE Runtime Environment (build 19.0.2+7-44)
    Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
    

    still has same problem.

    ———-solved———-

    update java and change environment variables location of JAVA_HOME

    Add this to gradle.properties

    org.gradle.java.home=C:\Program Files\Java\jdk-18.0.2.1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search