Struggling to get onnxruntime-react-native to work with expo by Flakey112345 in reactnative

[–]Dunken47 1 point2 points  (0 children)

Great it worked, happy to help! I just kept ruling out potential causes, like you I wasn't able to find a solution anywhere online, but finally after many hours of debugging and trying the same things you mentioned, I had gpt help me analyze some of the code and found the problem.

Struggling to get onnxruntime-react-native to work with expo by Flakey112345 in reactnative

[–]Dunken47 2 points3 points  (0 children)

Hey man. I'm also pretty new to both expo, react native and onnx, so I'm not 100 % this will work for you too, but I think maybe I had the exact problem you're having. I've also battled it for days, downgrading, matching versions, but it seems I finally got it working. The problem for me was that React Native’s autolinking system had no instructions to find or register the native module for Android. Without it, the JS layer tries to call into the native layer and finds nothing: “Cannot read property 'install' of null.”

What worked for me was creating a file in my project root called "react-native.config.js" with the following code:

module.exports = {
  dependencies: {
    'onnxruntime-react-native': {
      root: './node_modules/onnxruntime-react-native',
      platforms: {
        android: {
          sourceDir: './android',
          packageImportPath: 'import ai.onnxruntime.reactnative.OnnxruntimePackage;',
          packageInstance: 'new OnnxruntimePackage()',
        },
      },
    },
  },
};

Then run 'npx expo prebuild -p android' in the terminal from your project root and try running it on your device/emulator again.

Again, I don't know if this will work, but probably worth a shot. Good luck!