zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.1k stars 836 forks source link

[Android]: Failed to build gradle in monorepo. Unable to resolve react-native location in node_modules #847

Closed alex-vasylchenko closed 9 months ago

alex-vasylchenko commented 9 months ago

Bug summary

Project structure:
- root
  - node_modules
  - package.json
  - apps
    - mobile
      - android
      - package.json
Build file 'node_modules/react-native-permissions/android/build.gradle' line: 35

A problem occurred evaluating project ':react-native-permissions'.
[react-native-permissions] Unable to resolve react-native location in node_modules. You should add project extension property (in app/build.gradle) `REACT_NATIVE_NODE_MODULES_DIR` with path to react-native.

Library version

4.1.2

Environment info

System:
  OS: macOS 14.1.2
  CPU: (10) arm64 Apple M1 Max
  Memory: 151.73 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.11.0
    path: ~/.nvm/versions/node/v20.11.0/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 10.4.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.11.06.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.2
    path: /Users/whoami/.rvm/gems/ruby-2.7.7/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK:
    API Levels:
      - "28"
      - "30"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 32.1.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
    System Images:
      - android-32 | Google APIs ARM 64 v8a
      - android-32 | Google Play ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 2.7.7
    path: /Users/whoami/.rvm/rubies/ruby-2.7.7/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Reproducible sample code

// app/build.gradle

project.ext["REACT_NATIVE_NODE_MODULES_DIR"] = "../../../../../node_modules/react-native"

react {
    reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
    hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
    codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
    cliFile = new File(["node", "--print", "require.resolve('react-native/cli.js')"].execute(null, rootDir).text.trim())
    // REACT_NATIVE_NODE_MODULES_DIR = file("../../../../node_modules/react-native")
}
zoontek commented 9 months ago

@alex-vasylchenko Please create a repository for reproduction.

alex-vasylchenko commented 9 months ago

@zoontek hi, I created an identical project that has all the same settings as my production version and everything works flawlessly...idk what should I do.. looks like an error on my end, but I have no idea how to find it

alex-vasylchenko commented 9 months ago

my problem was due to problems with npm workspaces, i switched to yarn, now everything is ok