Running expo-camera in a react native app

I have a react native app and want to add the expo-camera (and maybe other packages) to it, but as I need native support, I use it in a plain react native project without expo.

I setup everything to compile the app successfully, but on the device I run into the error

Attempt to invoke virtual method ‘java.lang.Object’ expo.core.ModuleRegistry.getModule(java.lang.Class)’ on a null object reference.
inside initBarCodeScanner

It seems the mModuleRegistry reference isn’t passed to ExpoCameraView. Did I missed anything in my setup?

MainApplication.java

private final ModuleRegistryProvider mModuleRegistryProvider = new ModuleRegistryProvider(Arrays.<Package>asList(
    new ReactAdapterPackage(),
    new BarCodeScannerPackage(),
    new PermissionsPackage(),
    new CameraPackage()
));

...

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      new ModuleRegistryAdapter(mModuleRegistryProvider)
  );
}

Ok, after some testing and debugging, I got the whole thing running - but I had to modify the code of CameraViewManager.

As setModuleRegistry is not called from the UI Manager, I changed the visibility from mModuleRegistry to static. This way, the expo-react-native-adapter does the call and the var is later ready to use. This “Hack” works, but feels extremly bad and I hoped some of the devs have a better solution.

I also tried the NativeModulesProxy from expo-core, but that only returns me the CameraModule and not a view.

1 Like

Hey @pserrer!

What expo-react-native-adapter version do you use? AFAIR this issue could be fixed in expo-react-native-adapter@1.1.0 and expo-core@1.1.0. Could you please try out those or newer versions? :slightly_smiling_face:

Offending commits: adapter, core.

I tried the indicated versions but it still does not work.
it helped me: add static to mModuleRegistry

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.