mrousavy / react-native-fast-tflite

🔥 High-performance TensorFlow Lite library for React Native with GPU acceleration
https://mrousavy.com
MIT License
729 stars 40 forks source link

Execution failed for task ':react-native-fast-tflite:buildCMakeDebug[arm64-v8a] #99

Open francesco-clementi-92 opened 1 month ago

francesco-clementi-92 commented 1 month ago

I'm trying to add this library to my react native project, but I'm getting this error when I try to run on android:

Execution failed for task ':react-native-fast-tflite:buildCMakeDebug[arm64-v8a]'.
> com.android.ide.common.process.ProcessException: ninja: Entering directory `/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/.cxx/Debug/17534e6g/arm64-v8a' [1/4] Building CXX object CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorHelpers.cpp.o FAILED: CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorHelpers.cpp.o /Users/francescoclementi/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android26 --sysroot=/Users/francescoclementi/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DVisionCameraTflite_EXPORTS -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../cpp -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/src/main/cpp -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../tensorflow -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactCommon -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactCommon/callinvoker -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactAndroid/src/main/jni/react/turbomodule -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/2cabb25e97290c266f7cc06bcb971c95/transformed/react-android-0.75.4-debug/prefab/modules/jsi/include -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/2cabb25e97290c266f7cc06bcb971c95/transformed/react-android-0.75.4-debug/prefab/modules/reactnativejni/include -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/ac24feb11b9b575f8add13c9223c40a2/transformed/fbjni-0.6.0/prefab/modules/fbjni/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O2 -frtti -fexceptions -Wall -fstack-protector-all -DANDROID -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorHelpers.cpp.o -MF CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorHelpers.cpp.o.d -o CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorHelpers.cpp.o -c /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorHelpers.cpp In file included from /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorHelpers.cpp:9: /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../cpp/TensorHelpers.h:15:10: fatal error: 'tensorflow/lite/c/c_api.h' file not found #include <tensorflow/lite/c/c_api.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. [2/4] Building CXX object CMakeFiles/VisionCameraTflite.dir/src/main/cpp/Tflite.cpp.o FAILED: CMakeFiles/VisionCameraTflite.dir/src/main/cpp/Tflite.cpp.o /Users/francescoclementi/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android26 --sysroot=/Users/francescoclementi/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DVisionCameraTflite_EXPORTS -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../cpp -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/src/main/cpp -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../tensorflow -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactCommon -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactCommon/callinvoker -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactAndroid/src/main/jni/react/turbomodule -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/2cabb25e97290c266f7cc06bcb971c95/transformed/react-android-0.75.4-debug/prefab/modules/jsi/include -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/2cabb25e97290c266f7cc06bcb971c95/transformed/react-android-0.75.4-debug/prefab/modules/reactnativejni/include -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/ac24feb11b9b575f8add13c9223c40a2/transformed/fbjni-0.6.0/prefab/modules/fbjni/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O2 -frtti -fexceptions -Wall -fstack-protector-all -DANDROID -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/VisionCameraTflite.dir/src/main/cpp/Tflite.cpp.o -MF CMakeFiles/VisionCameraTflite.dir/src/main/cpp/Tflite.cpp.o.d -o CMakeFiles/VisionCameraTflite.dir/src/main/cpp/Tflite.cpp.o -c /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/src/main/cpp/Tflite.cpp In file included from /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/src/main/cpp/Tflite.cpp:7: /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../cpp/TensorflowPlugin.h:19:10: fatal error: 'tensorflow/lite/c/c_api.h' file not found #include <tensorflow/lite/c/c_api.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. [3/4] Building CXX object CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorflowPlugin.cpp.o FAILED: CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorflowPlugin.cpp.o /Users/francescoclementi/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android26 --sysroot=/Users/francescoclementi/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DVisionCameraTflite_EXPORTS -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../cpp -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/src/main/cpp -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../tensorflow -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactCommon -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactCommon/callinvoker -I/Users/francescoclementi/parkingless-mobile/node_modules/react-native/ReactAndroid/src/main/jni/react/turbomodule -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/2cabb25e97290c266f7cc06bcb971c95/transformed/react-android-0.75.4-debug/prefab/modules/jsi/include -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/2cabb25e97290c266f7cc06bcb971c95/transformed/react-android-0.75.4-debug/prefab/modules/reactnativejni/include -isystem /Users/francescoclementi/.gradle/caches/8.8/transforms/ac24feb11b9b575f8add13c9223c40a2/transformed/fbjni-0.6.0/prefab/modules/fbjni/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O2 -frtti -fexceptions -Wall -fstack-protector-all -DANDROID -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorflowPlugin.cpp.o -MF CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorflowPlugin.cpp.o.d -o CMakeFiles/VisionCameraTflite.dir/Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorflowPlugin.cpp.o -c /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorflowPlugin.cpp In file included from /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/cpp/TensorflowPlugin.cpp:9: /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/../cpp/TensorflowPlugin.h:19:10: fatal error: 'tensorflow/lite/c/c_api.h' file not found #include <tensorflow/lite/c/c_api.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. ninja: build stopped: subcommand failed. C++ build system [build] failed while executing: /Users/francescoclementi/Library/Android/sdk/cmake/3.22.1/bin/ninja \ -C \ /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android/.cxx/Debug/17534e6g/arm64-v8a \ VisionCameraTflite from /Users/francescoclementi/parkingless-mobile/node_modules/react-native-fast-tflite/android * Try:

I already tried deleted android/.gradle, clean the project, fresh install etc.

"react-native-vision-camera": "^4.5.3", "react-native": "^0.75.4", "react-native-fast-tflite": "^1.4.0",

maintenance-hans[bot] commented 1 month ago

Guten Tag, Hans here 🍻,

Thanks for reporting ze issue! It looks like you are missing a critical file from ze TensorFlow library: 'tensorflow/lite/c/c_api.h'. Please ensure that you have added TensorFlow correctly to your project.

Also, since you are running into build errors, I recommend checking if you have followed all installation instructions in ze documentation for react-native-fast-tflite. If ze problem persists, please try to provide more detailed logs or steps you took to reproduce ze issue.

If you find this library helpful, consider supporting its maintenance through sponsorship.

Let’s get this sorted!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

Pormons commented 4 weeks ago

any updates on this?

navxchahal commented 3 weeks ago

facing same issue, same configurations

ElMahdiAboulmanadel commented 3 weeks ago

Facing same issue!!

bilal1031 commented 3 weeks ago

Facing the same issue when trying to make an Android development build on expo.

navxchahal commented 3 weeks ago

It is because tensorflow folder is missing in ../node_modules/react-native-fast-tflite/cpp.

So, to make it work, download tensorflow manually and paste the tensorflow folder in ../node_modules/react-native-fast-tflite/cpp.

You don't need every folder in tensorflow. Just keep "lite" folder.

Screenshot 2024-10-31 at 10 14 38 PM
francesco-clementi-92 commented 3 weeks ago

Any reason why this bug exist? Should I make a PR with the tensorflow files copied in the repo?

bilal1031 commented 3 weeks ago

Any reason why this bug exist? Should I make a PR with the tensorflow files copied in the repo?

Making a PR would be good as I use EAS to make development builds in expo and It cannot download the files during the building process, It will just download the package and give me the error.

bilal1031 commented 2 weeks ago

Any update guys?

mateoabrbt commented 2 weeks ago

@mrousavy Could we have a fix for this issue? The iOS build isn’t working well on version 1.3.0, and the Android build has issues on version 1.4.0, which is causing inconvenience.

shreykul commented 2 weeks ago

@navxchahal Were you able to make it work by the method you mentioned above? I'm still not able to make it work.

bilal1031 commented 2 weeks ago

@navxchahal Were you able to make it work by the method you mentioned above? I'm still not able to make it work.

For iOS use version 1.4.0 For Android use version 1.3.0

This is the solution I found.

navxchahal commented 2 weeks ago

@navxchahal Were you able to make it work by the method you mentioned above? I'm still not able to make it work.

Yes, It is working for me on both iOS and Android on these versions.

"react-native-fast-tflite": "^1.4.0",
"react-native": "0.75.3",
"react-native-vision-camera": "^4.5.3",
"react-native-worklets-core": "^1.3.3",
"vision-camera-resize-plugin": "^3.1.0",

make sure you have copied exact folders in ../node_modules/react-native-fast-tflite/cpp then run ./gradlew clean once

shreykul commented 2 weeks ago

@navxchahal Maybe because I'm using the 0.76.1 version of react native that's why it is not working

shreykul commented 2 weeks ago

@bilal1031 even that's not working in the 0.76.1 version of react native... I'm thinking of downgrading the react native version then will try again later

bilal1031 commented 2 weeks ago

@bilal1031 even that's not working in the 0.76.1 version of react native... I'm thinking of downgrading the react native version then will try again later

That is correct, it worked for me because I am using the 0.74.5 version of react native

Betucciny commented 5 days ago

Any reason why this bug exist? Should I make a PR with the tensorflow files copied in the repo?

Making a PR would be good as I use EAS to make development builds in expo and It cannot download the files during the building process, It will just download the package and give me the error.

As previously mentioned, the error occurs because the necessary TensorFlow header (.h) files are missing. If you are using EAS to build your app, you can resolve this by using a postinstall script to patch the dependency. This approach allows the project to run with EAS both in the cloud and locally. I implemented this using patch-package, and it works flawlessly. Each time npm install is executed, it installs the dependencies and then patches this one with the required TensorFlow header files.

bfar97 commented 4 days ago

I managed to build my app (react-native@0.76) with version 1.5.0 by applying a patch with the changes in #108 and the files from tensorflow missing.

im-indian-techie commented 3 days ago

Execution failed for task ':react-native-fast-tflite:configureCMakeDebug[arm64-v8a]'. How to fix above issue i have tried lot of solutions but did'nt resolved yet?

mateoabrbt commented 3 days ago

I reviewed the latest merge, and it seems that this PR, particularly the Android changes, is not functioning as expected. I noticed that the CMakeLists file was modified to look for headers in the ../tensorflow directory, but there’s no tensorflow folder present when using this library. Additionally, cloning the entire tensorflow folder at the root of the project could significantly increase the app’s size, which is not an acceptable solution. I would recommend reverting the changes made in this PR on the Android side to the previous version instead.

laurencetroyv commented 2 days ago

for those who are still having trouble follow @navxchahal but also move copy the compiler, this works for me

| react-native-fast-tflite
    | - cpp
         | - tensorflow
               | - lite (folder)
               | - compiler (folder)