mrousavy / react-native-fast-tflite

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

[iOS]: "RNTfliteSpec.h" not found in RN 0.75 with new arch #87

Open mbpictures opened 2 months ago

mbpictures commented 2 months ago

Hi!

I'm using react-native 0.75 with the new architecture enabled and I'm getting an XCode compile error, that the file "RNTfliteSpec.h" could not be found in this line:

#import "RNTfliteSpec.h"

There was an issue regarding this problem but it has been closed without solving, so I'm creating a new one. Any help in addressing this problem would be highly appreciated! Thanks already!

maintenance-hans[bot] commented 2 months ago

Guten Tag, Hans here! 🍻

Thanks for your report! It looks like you're having trouble with the file "RNTfliteSpec.h" not being found. Please make sure you have followed all installation instructions and double-check your project setup with the documentation.

Also, could you please provide more information regarding your environment? Specifically, we need to know if there are any relevant logs from Xcode. You can find them in the Xcode logs window during the build process. This would greatly help mrousavy in diagnosing ze problem.

If you feel like this issue might be caused by something else, please feel free to update your post and we can take another look!

Danke!

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

lucksp commented 1 month ago

I get this error building for Android also.

liontariai commented 2 weeks ago

I think this happens, because there's no codegenConfig in the package.json for @react-native/codegen to generate the turbomodule header file.

https://github.com/mrousavy/react-native-fast-tflite/issues/14#issuecomment-1903497131

@mrousavy as you mentioned here, the file is missing, correct. But it's not that you would create it by hand. It seems it would be generated, if the config is set up properly. I found a tutorial here: https://medium.com/@sanchitsrivastava247/creating-turbo-module-in-react-native-0-74-73c6cae6a945

I'll try to fix this somehow and report back. Perhaps we can come up with a PR

liontariai commented 2 weeks ago

You can try my fork: https://github.com/liontariai/react-native-fast-tflite

1) Install from github with "react-native-fast-tflite": "liontariai/react-native-fast-tflite", 2) Copy the dir https://github.com/liontariai/react-native-fast-tflite/tree/main/src/expo-plugin into your root project 3) In withFastTFLite.ts replace const pkg = require('../../../package.json') with const pkg = require("react-native-fast-tflite/package.json"); 4) Use the plugin from your root project in your expo config. The reason for this is, that otherwise you'd be importing Typescript from a node_modules location which doesn't work. The correct fix for this would be to publish an updated package, but this is WIP.

mSenad commented 4 days ago

@liontariai do you have any information when it comes to bare workflow in react-native? I have the sam issue and this is my package.json file:

{
  "name": "PoseDetection",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-native": "0.76.1",
    "react-native-fast-tflite": "^1.5.0",
    "react-native-vision-camera": "^4.6.1",
    "react-native-worklets-core": "^1.5.0"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@babel/preset-env": "^7.25.3",
    "@babel/runtime": "^7.25.0",
    "@react-native-community/cli": "15.0.0",
    "@react-native-community/cli-platform-android": "15.0.0",
    "@react-native-community/cli-platform-ios": "15.0.0",
    "@react-native/babel-preset": "0.76.1",
    "@react-native/eslint-config": "0.76.1",
    "@react-native/metro-config": "0.76.1",
    "@react-native/typescript-config": "0.76.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.3.1",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

I've got nothing much happening here yet but my build is failing just because I have "react-native-fast-tflite" installed. Thanks!

lucksp commented 4 days ago

but my build is failing just because I have "react-native-fast-tflite" installed

What is the build failure message?

mSenad commented 4 days ago

@lucksp Thanks for hopping in.

So, currently I uninstall 'react-native-fast-tflite' and tried to build my app and everything works as expected.

When I:

This is everything I do, than I go to build my app from the xcode and here is the error:

Screenshot 2024-11-12 at 4 23 52 PM
liontariai commented 4 days ago

Hey @mSenad , I'll try my best:

I think generally you need to do the exact same thing I did, the error you see is what I saw. The problem is that the package is not fully implemented as TurboModule, which is required (?) for the new architecture.

So if you follow the steps I have outlined above, you should be able to fix it. The only thing that's different, is that you'll be doing the things that are done by the expo plugins manually.

If I see it right, the plugin only adds a variable to your Podfile and adds a Framework to the XCode project: grafik

And this is also only done, if you want to use the CoreML Delegates (i'm no expert on what it is / why you'd need it... i think it's like GPU/NeuralEngine acceleration?) grafik

So therefore, you might as well skip the expo plugins / Podfile modifications and might still work... Give it a try and report back, so I might help you further if needed ;)

mSenad commented 4 days ago

@liontariai thanks man, I really appreciate it that you took your time to give me some insights.

Currently, when I run npm install liontariai/react-native-fast-tflite my terminal just stucks. Is there something that I need to do here in order to have this package installed or?

...and how I understood, I just need to have expo-plugin folder in my project root level and apply the changes you've mentioned, right?

liontariai commented 4 days ago

you're welcome! Well... I'm not 100% sure why it stucks. I have installed it by putting it in my package.json and running the install then, I'm not sure how you tell npm to look at github via the cli command, even though it might be correct the way you did it.

grafik

Also you could check if you have some logs for npm. I think it prints logs somewhere in the /tmp dir. Could be that there's some post-install script running a pod install maybe? I'm not sure but if I remember correctly, the pod install can take some time...

Regarding the plugins... if you don't use expo, you shouldn't need to do anything other than installing the package from my repo.

mSenad commented 4 days ago

@liontariai for some reason I am not able to install your fork of the repo... I've tried with adding "react-native-fast-tflite": "liontariai/react-native-fast-tflite", to my package.json and by running npm install directly but it's just stucked.

I see your latest commit inside the forked repo so maybe I can just apply the same changes and try to use my own fork. That's the only thing that comes to my mind at the moment.

Appreciate your effort man!

liontariai commented 4 days ago

Yes, you can definitely do that. You can try your own fork, or for the time being just apply the changes in your locally installed pkg. I only made a fork so that it would be somewhat consistent and not vanish after a fresh install of packages... and also to have a starting point to make a contribution back to this package.