shaqian / tflite-react-native

React Native library for TensorFlow Lite
https://www.npmjs.com/package/tflite-react-native
MIT License
289 stars 108 forks source link

iOS: null is not an object evaluating TfliteReactNative.loadmodel #1

Closed ojiofong closed 5 years ago

ojiofong commented 5 years ago

First of all, thanks for this awesome project. Had this working on Android but not quite on iOS. The home screen with the buttons shows up. However, clicking on a button results in error: null is not an object evaluating TfliteReactNative.loadmodel

The only change I made was in the Pod file to get the build to succeed.

Pod file:

platform :ios, '9.0'

target 'example' do
  pod 'TensorFlowLite', '1.12.0'
  pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'

  pod 'React', :path => '../node_modules/react-native'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

end

My npm version is 6.5.0

Need help with resolving this. Thanks.

shaqian commented 5 years ago

Hi,

Can you please try to manually link the library to your project? https://github.com/shaqian/tflite-react-native#ios

Thanks, Qian

ojiofong commented 5 years ago

Thank you, Qian. I was finally able to resolve the issue by making some additional changes to the Pod file. However, I'll manually link the library later as well. Maybe it could fix this, but I had previously checked to make sure that all the files were added correctly via automatic linking.

techgig17 commented 5 years ago

Thank you, Qian. I was finally able to resolve the issue by making some additional changes to the Pod file. However, I'll manually link the library later as well. Maybe it could fix this, but I had previously checked to make sure that all the files were added correctly via automatic linking.

Can you provide me the podfile changes you made to make it work?

ojiofong commented 5 years ago

Thank you, Qian. I was finally able to resolve the issue by making some additional changes to the Pod file. However, I'll manually link the library later as well. Maybe it could fix this, but I had previously checked to make sure that all the files were added correctly via automatic linking.

Can you provide me the podfile changes you made to make it work?

Here you go.

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'TurdsWithFriends' do
  pod 'TensorFlowLite', '1.12.0'
  pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'
  pod 'React', :path => '../node_modules/react-native'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'TfliteReactNative', :path => '../node_modules/tflite-react-native/ios'

end

# Workaround for RN upgrade issues: https://github.com/facebook/react-native/issues/24192
post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "React"
      target.remove_from_project
    end
  end
end
kashifsulaiman commented 5 years ago

@ojiofong since you're using POD, so you didn't had done the manual linking except the Podfile part, right? I did the same, but I'm getting image

Actually in TfliteReactNative.loadModel, TfliteReactNative is undefined which is destructed from NativeModules

hokaiyipFS commented 4 years ago

Manually linking with iOS fixed my issue

Tayyaba3317 commented 3 years ago

@hokaiyipFS which react native version are you using?

hokaiyipFS commented 3 years ago

@Tayyaba3317 0.63.2

lucidprojects commented 3 years ago

Sorry to rehash an old thread but I'm having this same issue. And have tried the above fixes with no luck.

It does work if I build it to Android, which makes me think I have the model files in the wrong place.

This is where I have them currently: /ios/AppName/models

Any help appreciated.

BILLXZY1215 commented 3 years ago

Sorry to rehash an old thread but I'm having this same issue. And have tried the above fixes with no luck.

It does work if I build it to Android, which makes me think I have the model files in the wrong place.

This is where I have them currently: /ios/AppName/models

Any help appreciated.

Same issue. I tried manual link, however, when I try to build model in XCode, I get this:

截屏2021-09-02 下午10 46 12

https://stackoverflow.com/questions/41663002/react-rctbridgemodule-h-file-not-found#comment76499068_43340802

The link above mentioned some possible solutions. I think this is related to the version of React Native (>0.61).

Well, I fixed it by adding conditional import in RCTBridgeModule.h (after manual link, and follow the instruction in stackoverflow above):

#if __has_include("RCTDefines.h")
#import "RCTDefines.h"
#else
#import <React/RCTDefines.h>
#endif
lucidprojects commented 3 years ago

Same issue. I tried manual link, however, when I try to build model in XCode, I get this:

This comment helped me sort a similar RCTBridge issue.

Then just make sure you build it from Xcode from the xcworkspace not the xcodeproj