react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

🐛 [Android] - Does not build within monorepo

Open batical opened this issue 3 years ago • 12 comments

What were you trying to do?

Trying to build on android with a Monorepo with version 2.5.0

Previous version was working fine

What happened instead?

Where:
Build file '[...]/node_modules/react-native-vision-camera/android/build.gradle' line: 220

* What went wrong:
A problem occurred evaluating project ':react-native-vision-camera'.
> Expected directory '[...]/packages/mobile/android/../node_modules/react-native/android' to contain exactly one file, however, it contains no files.

I changed the path on : line 220, 221, 223, 229

but got C compilation error fatal error: 'jsi/jsi.h' file not found

after updating l97 the build command is working

Relevant log output

No response

Device

Android

VisionCamera Version

2.5.0

Additional information

batical avatar Aug 06 '21 15:08 batical

Interesting, does this work if you create a symlink to node_modules in the mobile/ directory?

mrousavy avatar Aug 06 '21 17:08 mrousavy

I will try to give a try next week. (for now I created a patch-package for my case).

batical avatar Aug 07 '21 08:08 batical

@batical what did you fix on patch package?

zifahm avatar Aug 20 '21 06:08 zifahm

Here is the content on my patch package

diff --git a/node_modules/react-native-vision-camera/android/build.gradle b/node_modules/react-native-vision-camera/android/build.gradle
index 7c74d37..1b66ee2 100644
--- a/node_modules/react-native-vision-camera/android/build.gradle
+++ b/node_modules/react-native-vision-camera/android/build.gradle
@@ -94,7 +94,7 @@ android {
         cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
         abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
         arguments '-DANDROID_STL=c++_shared',
-                "-DNODE_MODULES_DIR=${rootDir}/../node_modules",
+                "-DNODE_MODULES_DIR=${rootDir}/../../../node_modules",
                 "-DFOR_HERMES=${FOR_HERMES}"
       }
     }
@@ -217,16 +217,16 @@ dependencies {
   //noinspection GradleDynamicVersion
   extractJNI("com.facebook.fbjni:fbjni:+")
 
-  def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
-  def jscAAR = fileTree("${rootDir}/../node_modules/jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
+  def rnAAR = fileTree("${rootDir}/../../../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
+  def jscAAR = fileTree("${rootDir}/../../../node_modules/jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
 
-  def inputFile = new File(rootDir, '../node_modules/react-native/package.json')
+  def inputFile = new File(rootDir, '../../../node_modules/react-native/package.json')
   def json = new JsonSlurper().parseText(inputFile.text)
   def reactNativeVersion = json.version as String
   def (major, minor, patch) = reactNativeVersion.tokenize('.')
 
   def jsEngine = FOR_HERMES ? "hermes" : "jsc"
-  def reaAAR = "${rootDir}/../node_modules/react-native-reanimated/android/react-native-reanimated-${minor}-${jsEngine}.aar"
+  def reaAAR = "${rootDir}/../../../node_modules/react-native-reanimated/android/react-native-reanimated-${minor}-${jsEngine}.aar"
 
   extractJNI(files(rnAAR, jscAAR, reaAAR))
 
@@ -274,7 +274,7 @@ task extractJNIFiles {
 
 def downloadsDir = new File("$buildDir/downloads")
 def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
-def thirdPartyVersionsFile = new File("${rootDir}/../node_modules/react-native/ReactAndroid/gradle.properties")
+def thirdPartyVersionsFile = new File("${rootDir}/../../../node_modules/react-native/ReactAndroid/gradle.properties")
 def thirdPartyVersions = new Properties()
 thirdPartyVersions.load(new FileInputStream(thirdPartyVersionsFile))

batical avatar Aug 26 '21 18:08 batical

@batical thanks :+1:

zifahm avatar Sep 01 '21 07:09 zifahm

working also with last versions 2.6.1 in debug or release mode

batical avatar Sep 01 '21 09:09 batical

@mrousavy I've encountered the same issue right now while trying to install it in my monorepo setup. iOS is working flawlessly. Maybe this one is helpful for you: https://github.com/software-mansion/react-native-gesture-handler/pull/1757/files

This is how react-native-gesture-handler fixed that issue for monorepos when trying to determine react-native-reanimated version

hirbod avatar Dec 18 '21 20:12 hirbod

I encountered this at RN 0.69.1 and solved it temporarily by replacing line 228 in the android/build.gradle file of react-native-vision-camera (in node_modules) by def rnAAR = fileTree("${nodeModules}/react-native/android/com/facebook/react/react-native/0.69.1").matching({ it.include "**/**/*-release.aar" }).singleFile Here, the word release could also be exchanged by debug, i guess. Beware, that every reinstall of node_modules will wipe this change from the file.

Alexispap avatar Jul 01 '22 18:07 Alexispap

I have the same problem and still not resolved @mrousavy

mrozkosz avatar Jul 05 '22 17:07 mrozkosz

Not sure what you are doing, but I have a monorepo setup (0.68.2) and it's working fine

hirbod avatar Jul 05 '22 17:07 hirbod

As you can see when I build the application I get this error.

Zrzut ekranu 2022-07-5 o 20 18 19

Zrzut ekranu 2022-07-5 o 20 22 14

"react-native-vision-camera": "^2.13.5", "react-native-reanimated": "^2.9.1" "react-native": "0.69.1",

java version "16.0.1"

What is the problem? @hirbod, without react-native-reanimated I can build the application, but I need this...

mrozkosz avatar Jul 05 '22 18:07 mrozkosz

I don't know. And I am not sure why you Tag so many random people which aren't even involved

hirbod avatar Jul 05 '22 18:07 hirbod