react-native: Android build of clean sample project fails during dependency resolution

Description

When I setup a fresh project as per the docs using:

npx react-native@latest init RNTestApp

And then try to run it using:

 npx react-native run-android

I get this error:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not determine the dependencies of null.
   > Cannot query the value of this provider because it has no value available.

* 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

React Native Version

0.72.0

Output of npx react-native info

info Fetching system and libraries information...
System:
  OS: macOS 13.2
  CPU: (10) arm64 Apple M1 Pro
  Memory: 72.66 MB / 32.00 GB
  Shell:
    version: 5.8.1
    path: /bin/zsh
Binaries:
  Node:
    version: 18.12.1
    path: ~/.nvm/versions/node/v18.12.1/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v18.12.1/bin/yarn
  npm:
    version: 8.19.2
    path: ~/.nvm/versions/node/v18.12.1/bin/npm
  Watchman:
    version: 2022.10.24.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/daniel/.rvm/gems/ruby-3.0.0/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK:
    API Levels:
      - "26"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
    Build Tools:
      - 28.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
    System Images:
      - android-31 | Google APIs ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
    Android NDK: 23.1.7779620
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.1
    path: /usr/bin/javac
  Ruby:
    version: 3.0.0
    path: /Users/daniel/.rvm/rubies/ruby-3.0.0/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.0
    wanted: 0.72.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

  • npx react-native@latest init RNTestApp
  • cd RNTestApp
  • npx react-native run-android

Snack, code example, screenshot, or link to a repository

Above reproducible is available at cnixbtc/RNTestApp.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

@cnixbtc yes please try to build with Java 11 and report back. I’m not aware of any incompatibilities between Java 17 and React Native 0.72, but this could be one.

Facing the same issue here.

If I use Java 11, I’m getting below error

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
      Your current JDK is located in /opt/homebrew/Cellar/openjdk@11/11.0.19/libexec/openjdk.jdk/Contents/Home
      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`.

And if I go with Java 17 then it results in

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':react-native:packages:react-native:ReactAndroid:bundleLibCompileToJarDebug'.
> Could not create task ':react-native:packages:react-native:ReactAndroid:compileDebugJavaWithJavac'.
   > Failed to calculate the value of task ':react-native:packages:react-native:ReactAndroid:compileDebugJavaWithJavac' property 'javaCompiler'.
      > No matching toolchains found for requested specification: {languageVersion=11, vendor=any, implementation=vendor-specific}.
         > No locally installed toolchains match (see https://docs.gradle.org/8.0.1/userguide/toolchains.html#sec:auto_detection) and toolchain download repositories have not been configured (see https://docs.gradle.org/8.0.1/userguide/toolchains.html#sub:download_repositories).

My issue got sorted out after I manually placed both jdk 17 & jdk 11 under ~/.gradle/jdks folder. Gradle was not auto downloading the jdks required in the toolchain.

@cnixbtc yes please try to build with Java 11 and report back. I’m not aware of any incompatibilities between Java 17 and React Native 0.72, but this could be one.

will retry later this week and report back.

maybe it’s because your Java version is 17 and not 11?