facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.16k stars 24.21k forks source link

Android build of clean sample project fails during dependency resolution #38056

Closed cnixbtc closed 1 year ago

cnixbtc commented 1 year ago

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

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

Above reproducible is available at cnixbtc/RNTestApp.

cortinico commented 1 year ago

Steps to reproduce

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

I'm sorry but I cannot reproduce this issue. Is this happening for every React Native version you try?

cnixbtc commented 1 year ago

Hi @cortinico, thanks for the quick reply. Let me double check with other versions of React Native. I'll also give it a try on a second machine. Will report back.

cnixbtc commented 1 year ago

I just tried the same thing with React Native 0.70.5 (which I know worked on my machine before) and everything just worked:

npx react-native@0.70.5 init RNTestApp0705 --version="0.70.5"
cd RNTestApp0705
npx react-native run-android

Tried again with 0.72.0 and it didn't work (same issue as reported above). I think my Android environment is correctly setup (see react-native info output above) so not sure what could be causing this. But since you cannot reproduce it maybe it's some other quirk related to my local setup.

I'm not blocked by this, I just found it interesting and wanted to bring it up. Feel free to close the issue if you want. :)

kelset commented 1 year ago

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

cortinico commented 1 year ago

@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.

longjiecn commented 1 year ago

@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.

I also got the same error but my java version is 11.

npx react-native doctor

Common ✓ Node.js - Required to execute JavaScript code ✓ yarn - Required to install NPM dependencies ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android ✓ Adb - Required to verify if the android device is attached correctly ✓ JDK - Required to compile Java code ✓ Android Studio - Required for building and installing your app on Android ✓ Android SDK - Required for building and installing your app on Android ✓ ANDROID_HOME - Environment variable that points to your Android SDK installation

iOS ✓ Xcode - Required for building and installing your app on iOS ✓ Ruby - Required for installing iOS dependencies ✓ CocoaPods - Required for installing iOS dependencies ● ios-deploy - Required for installing your app on a physical device with the CLI ✖ .xcode.env - File to customize Xcode environment

npx react-native info info Fetching system and libraries information... System: OS: macOS 12.6 CPU: (8) arm64 Apple M1 Memory: 449.84 MB / 16.00 GB Shell: version: 5.8.1 path: /bin/zsh Binaries: Node: version: 16.17.1 path: /usr/local/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 8.15.0 path: /usr/local/bin/npm Watchman: version: 2022.10.03.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.11.3 path: /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms:

cnixbtc commented 1 year ago

@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.

mattg95 commented 1 year ago

I'm having the same problem with Java 17 and React Native 0.72. I downgraded to Java 11, but got the same error. edit: output of npx react-native info:


System:
  OS: macOS 12.4
  CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Memory: 758.89 MB / 16.00 GB
  Shell:
    version: 5.8.1
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.1
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.homebrew/bin/yarn
  npm:
    version: 9.5.1
    path: /usr/local/bin/npm
  Watchman:
    version: 2023.06.12.00
    path: /Users/matt/.homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/matt/.rvm/gems/ruby-3.2.2/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 21.2
      - iOS 15.2
      - macOS 12.1
      - tvOS 15.2
      - watchOS 8.3
  Android SDK:
    API Levels:
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 34.0.0
    System Images:
      - android-25 | Google APIs Intel x86 Atom
      - android-27 | Google APIs Intel x86 Atom
      - android-31 | Google APIs Intel x86_64 Atom
      - android-32 | Google APIs Intel x86_64 Atom
      - android-33 | Google APIs Intel x86_64 Atom
      - android-34 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.9862592
  Xcode:
    version: 13.2.1/13C100
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.19
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /Users/matt/.rvm/rubies/ruby-3.2.2/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
hanarotg commented 1 year ago

Could you share your error messages created while building YOUR_PROJECT/android with android studio?

aswin-s commented 1 year ago

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.

cortinico commented 1 year ago

Hey @cnixbtc is your problem solved?

leolo784 commented 1 year ago

I am having the same error with Java 11 & react native 0.72.3

System:
  OS: macOS 12.2.1
  CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Memory: 336.00 MB / 16.00 GB
  Shell:
    version: "5.8"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.0
    path: ~/.nvm/versions/node/v18.16.0/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 9.5.1
    path: ~/.nvm/versions/node/v18.16.0/bin/npm
  Watchman:
    version: 2023.07.10.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.11.3
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 21.4
      - iOS 15.5
      - macOS 12.3
      - tvOS 15.4
      - watchOS 8.5
  Android SDK:
    API Levels:
      - "28"
      - "29"
      - "31"
      - "33"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
    System Images:
      - android-33 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2020.3 AI-203.7717.56.2031.7583922
  Xcode:
    version: 13.4.1/13F100
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.20
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /Users/lohungwai/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.3
    wanted: 0.72.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false
cortinico commented 1 year ago

Closing as @cnixbtc is unresponsive. If you folks have similar problem, please open a new issue

JAIRAJ28 commented 1 year ago

System: OS: Windows 10 10.0.22621 CPU: "(16) x64 AMD Ryzen 7 4800H with Radeon Graphics " Memory: 5.13 GB / 15.42 GB Binaries: Node: version: 16.16.0 path: C:\Program Files\nodejs\node.EXE Yarn: Not Found npm: version: 8.11.0 path: C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: AllowDevelopmentWithoutDevLicense: Enabled IDEs: Android Studio: AI-223.8836.35.2231.10406996 Visual Studio: Not Found Languages: Java: 11.0.20 Ruby: Not Found npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.4 wanted: 0.72.4 react-native-windows: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: Not found newArchEnabled: Not found

I have installed the sdk and have set the environment , but then also it shows sdk is not installed? Can you help me with this

hihelper commented 11 months ago

I have a problem...

I try to run it using:

yarn android

I get this error:

image

`PS C:\Windows\System32\aaa\AwesomeProject> yarn android yarn run v1.22.19 $ react-native run-android info JS server already running. info Installing the app... 5 actionable tasks: 5 up-to-date

info 💡 Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor

FAILURE: Build failed with an exception.

BUILD FAILED in 6s error Failed to install the app. info Run CLI with --verbose flag for more details. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. PS C:\Windows\System32\aaa\AwesomeProject> `

image

image

Here is git url

i'm so... newbie.. i'm trying to solve that problem. 3days.... but i can't..

yellowberard commented 7 months ago

Same it is one issue after another but I am not able to solve this one