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

Error when building for Android 🐛

Open Altequer opened this issue 3 years ago • 27 comments

What were you trying to do?

Whenever I go to build, an error occurs saying that the file is missing. I've tested with other versions but still. Could anyone help?

Reproduceable Code

gradlew assembleRelease

What happened instead?

Screenshot_1 dependencies.txt

Relevant log output

The following error always occurs:
C/C++: ../../../../build/third-party-ndk/folly\folly/dynamic.h:63:10: fatal error: 'boost/operators.hpp' file not found

Device

Android

VisionCamera Version

2.12.2

Additional information

Altequer avatar Mar 15 '22 16:03 Altequer

I'm facing the same issue

  ../../../../build/third-party-ndk/folly\folly/dynamic.h:63:10: fatal error: 'boost/operators.hpp' file not found
  #include <boost/operators.hpp>
           ^~~~~~~~~~~~~~~~~~~~~
 1 error generated.
  [9/10] Building CXX object CMakeFiles/VisionCamera.dir/src/main/cpp/CameraView.cpp.o
  ninja: build stopped: subcommand failed.

Jamal-Nazzal avatar Mar 16 '22 00:03 Jamal-Nazzal

Hey!

Could you try running ./gradlew clean before the release build, see if that helps? Does it work in debug?

mrousavy avatar Mar 16 '22 09:03 mrousavy

When I try this: go to \node_modules\react-native-vision-camera\android\build\third-party-ndk I find the boost folder named "boost_1_63_0", I rename it to just "boost". the build works, but this time I get the following error in the react-native start terminal


throw ex;
          ^

Error: EPERM: operation not permitted, lstat '[project directory]\node_modules\react-native-vision-camera\android\build\intermediates\cxx\Debug\4x231b5p\obj\arm64-v8a\libVisionCamera.so.tmp2ab35ca'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> ([project directory]\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (node:fs:198:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: '[project directory]\\node_modules\\react-native-vision-camera\\android\\build\\intermediates\\cxx\\Debug\\4x231b5p\\obj\\arm64-v8a\\libVisionCamera.so.tmp2ab35ca'
}

and if I delete the build and .cxx folders, then start clean cache, it builds fine but again crashes if I rebuild.

Jamal-Nazzal avatar Mar 16 '22 10:03 Jamal-Nazzal

I ran it but the error remains when I generate the apk

image image

Altequer avatar Mar 16 '22 13:03 Altequer

Please check my comment above. inside \node_modules\react-native-vision-camera\android\build\third-party-ndk there is a folder that should be named boost for some reason it gets named boost_1_63_0 that's why boost/operators.hpp can't be found. If you rename it to the correct name boost the error goes away. that's not a solution AT ALL, I'm posting this to make you aware of the source of the problem.

Jamal-Nazzal avatar Mar 16 '22 19:03 Jamal-Nazzal

If removing '_1_63_0' from the name really works, is there any way to definitively resolve this?

Altequer avatar Mar 18 '22 17:03 Altequer

the first time visionCamera builds it installs this library https://github.com/react-native-community/boost-for-react-native something wrong happens there. sometimes it builds fine and creates a folder called boost, other times it names it boost_1_63_0 and as a result boost/operators.hpp can't be found. Can't be clearer than this honestly. can this be definitively resolved? I don't know, mrousavy might be able to solve it.

Jamal-Nazzal avatar Mar 18 '22 21:03 Jamal-Nazzal

I'm getting this issue when building for production. In development, it builds fine.

jslok avatar Mar 21 '22 23:03 jslok

Same issue for me. Vision camera download "boost_${BOOST_VERSION}.tar.gz" from github, unzip it.

After that, in doLast block of the prepareBoost task renames the file to boost: image

but the file is not renamed for some reason. So we got "'boost/operators.hpp' file not found" error.

Manually rename folder after first build works for me

RafaelA977 avatar Apr 25 '22 10:04 RafaelA977

@RafaelA977 found the problem in the build.gradle file (see above). The reason is, that gradle cannot rename the directory (from boost_1_63_0 to boost). For more details see gradle documentation "Gradle has no API for moving files and directories around, but you can use the Apache Ant integration to easily do that"

https://docs.gradle.org/current/userguide/working_with_files.html#sec:moving_files_example

Solution:

Comment (or remove) the line

//file("$thirdPartyNdkDir/boost_${BOOST_VERSION}").renameTo("$thirdPartyNdkDir/boost")

and replace it with

ant.move(file: "$thirdPartyNdkDir/boost_${BOOST_VERSION}", tofile: "$thirdPartyNdkDir/boost", quiet: "false")

formifan2002 avatar May 02 '22 06:05 formifan2002

Now I'm getting this error Error: EPERM: operation not permitted, lstat 'C:\Users\...\app\node_modules\react-native-vision-camera\android\build\intermediates\cxx\Debug\602l1f37\obj\arm64-v8a\libVisionCamera.so.tmp50c975e' Emitted 'error' event on NodeWatcher instance at: at NodeWatcher.<anonymous> (C:\Users\...\app\node_modules\sane\src\node_watcher.js:291:16) at FSReqCallback.oncomplete (node:fs:198:21) { errno: -4048, code: 'EPERM', syscall: 'lstat', path: 'C:\\Users\\...\\app\\node_modules\\react-native-vision-camera\\android\\build\\intermediates\\cxx\\Debug\\602l1f37\\obj\\arm64-v8a\\libVisionCamera.so.tmp50c975e' }

Jamal-Nazzal avatar May 02 '22 16:05 Jamal-Nazzal

Hello ! I have a similar error with folly and I think that is the same : node_modules/react-native/ReactCommon/cxxreact/CxxModule.h:15:10: fatal error: 'folly/dynamic.h' file not found

I needed to disable FrameProcessors to build (https://mrousavy.com/react-native-vision-camera/docs/guides/frame-processors/#android) but we will soon need frame processors :/

MorvanL avatar May 04 '22 15:05 MorvanL

@MorvanL: before first correct "gradlew build" you must (!) run a "gradlew clean". Otherwise the gradlew build might not process correctly since some parts (e.g. folly...tar.gz) have been downloaded already during earlier builds and will not be processed correctly. Check after the clean and before the build, if directory "react-native-vision-camera\android\build" is empty. If not, delete any content in the directory manually and start the build.

formifan2002 avatar May 05 '22 04:05 formifan2002

@formifan2002 I did some tests: If I only run gradlew assembleRelease it works.

When I run gradlew clean assembleRelease I have : success, failed, success, failed, .... But if I run gradlew clean then gradlew assembleRelease it works. However in both cases I could see that the "react-native-vision-camera\android\build" file is correctly deleted

On our CI using fastlane and running gradlew clean assembleRelease, it fails every time. May be because there is more clean and yarn install between each build (i don't know details of our CI)

MorvanL avatar May 05 '22 09:05 MorvanL

I think we can work around but there must be a problem in the build process

MorvanL avatar May 05 '22 09:05 MorvanL

Sorry for spam. When it fails I don't have the lib folly in the react-native-vision-camera/android/build/third-party-ndk folder I have only hermes and jsc folder.

MorvanL avatar May 05 '22 09:05 MorvanL

I found a solution to solve this problem. With this patch for build.gradle it works for me: image

RafaelA977 avatar May 06 '22 17:05 RafaelA977

Getting the following error with version 2.13.3:

Error: ENOENT: no such file or directory, lstat '/Users/dev/app/node_modules/react-native-vision-camera/android/build/third-party-ndk/boost_1_63_0
Emitted 'error' event on FSEventsWatcher instance at:
    at Walker.emit (node:events:526:28)
    at /Users/dev/app/node_modules/walker/lib/walker.js:52:12
    at FSReqCallback.oncomplete (node:fs:198:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/Users/dev/app/node_modules/react-native-vision-camera/android/build/third-party-ndk/boost_1_63_0'
}

There is a folder .../node_modules/react-native-vision-camera/android/build/third-party-ndk/boost/boost

How can I build the production version without error?

I have been working on the development build including frame processors no problem.

ThaJay avatar May 30 '22 15:05 ThaJay

If I rename the first folder boost to boost_1_63_0, I get the following error:

In file included from /Users/dev/app/node_modules/react-native/ReactAndroid/src/main/jni/react/jni/NativeMap.h:11:
  ../../../../build/third-party-ndk/folly/folly/dynamic.h:63:10: fatal error: 'boost/operators.hpp' file not found
  #include <boost/operators.hpp>
           ^~~~~~~~~~~~~~~~~~~~~

ThaJay avatar May 31 '22 09:05 ThaJay

@RafaelA977 Was it too much trouble to copy the text?

eachFile { fname -> fname.path = (fname.path - "boost_${BOOST_VERSION}/")}
into("$thirdPartyNdkDir/boost")

After applying your patch, I get another error:


> Task :app:bundleReleaseJsAndAssets FAILED
/Users/dj/dev/chipta/scan-app/node_modules/metro-hermes-compiler/src/emhermesc.js:77
          throw ex;
          ^

Error: ENOENT: no such file or directory, lstat '/Users/dev/app/node_modules/react-native-vision-camera/android/.cxx/cmake/release/armeabi-v7a/CMakeFiles/CMakeTmp/CMakeFiles/TargetDirectories.txt'
Emitted 'error' event on FSEventsWatcher instance at:
    at Walker.emit (node:events:526:28)
    at /Users/dev/app/node_modules/walker/lib/walker.js:52:12
    at FSReqCallback.oncomplete (node:fs:198:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/Users/dev/app/node_modules/react-native-vision-camera/android/.cxx/cmake/release/armeabi-v7a/CMakeFiles/CMakeTmp/CMakeFiles/TargetDirectories.txt'
}

ThaJay avatar Jun 02 '22 12:06 ThaJay

I went ahead and tried older versions. 2.13.1 is the latest version that builds for me. "react-native-vision-camera": "2.13.1",

ThaJay avatar Jun 02 '22 13:06 ThaJay

I don't know why but today I got the error on 2.13.1 but on the latest version (2.13.5) it builds production just fine. (I did nuke my node_modules folder and cleaned my Gradle build files on both versions)

ThaJay avatar Jun 28 '22 14:06 ThaJay

For some reason it did not build any more but weirdly enough the latest version (2.13.5) did work this time. This confuses me but I'm glad it works.

ThaJay avatar Jul 07 '22 13:07 ThaJay

Hi, @MorvanL . Have you resolved issue in your case ?

ApWin77 avatar Aug 31 '22 09:08 ApWin77

Hi, sorry @ApWin77 I just saw your message. Until now we didn't need the frame processor so we disabled them. But now we need them for our barcode scanner and according to my first tests the problem is still there. It seems that doing gradlew clean before gradlew assembleRelease does not solve the problem anymore. I haven't tested the patch described above, but is there any chance that the problem will be fixed? We use RN 0.69.4 and I tried with and without Hermes enable

MorvanL avatar Sep 09 '22 07:09 MorvanL

Oh my bad, seems working with gradlew clean before gradlew assembleRelease (and not gradlew clean assembleRelease together). But I have to test with our CI and for the moment I have another error. I'll let you know once I've tested everything

MorvanL avatar Sep 09 '22 09:09 MorvanL

it's a workaround but I confirm that it works

MorvanL avatar Sep 09 '22 13:09 MorvanL