Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is ReactInstanceManager in my MainActivity.java file?

For the android installation of this component: https://github.com/lwansbrough/react-native-camera

The first installation step is:

Modify the ReactInstanceManager.builder() calls chain in android/app/main/java/.../MainActivity.java to include:

.addPackage(new RCTCameraPackage())

But my MainActivity.java file located at

android/app/src/main/java/com/.../MainActivity.java

Doesn't seem to have any reference to ReactInstanceManager.

Here it is in it's entirety:

package com.app;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import com.rssignaturecapture.RSSignatureCapturePackage;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "app";
    }

    /**
     * Returns whether dev mode should be enabled.
     * This enables e.g. the dev menu.
     */
    @Override
    protected boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
    }

   /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new RSSignatureCapturePackage(this),
        new MainReactPackage()
      );
    }
}

EDIT: This seems to be related to changes in React 0.18 Here is a similar issue / solution on another Module: https://github.com/marcshilling/react-native-image-picker/issues/74

I've tried applying the same changes to this Module as well with no luck.

like image 479
Dan G Nelson Avatar asked Jan 26 '16 15:01

Dan G Nelson


2 Answers

I was able to solve the same issues with the following steps:

  1. Installed react-native-camera from github and not with version "latest" but with github link

    npm install react-native-camera@https://github.com/lwansbrough/react-native-camera.git --save

(thank you https://github.com/lwansbrough/react-native-camera/issues/164)

  1. In file "/node_modules/react-native-camera/android/src/main/AndroidManifest.xml" I added the following permissions

    <uses-permission android:name="android.permission.CAMERA" />

    <uses-feature android:name="android.hardware.camera" />

    <uses-feature android:name="android.hardware.camera.autofocus" />

  2. In file "/node_modules/react-native-camera/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraViewManager.java" I modified the part

public class RCTCameraViewManager extends SimpleViewManager

to

public class RCTCameraViewManager extends ViewGroupManager

(thank you for 2. and 3. to https://github.com/lwansbrough/react-native-camera/issues/165)

  1. In File "/android/app/src/main/java/com/myapp/MainActivity.java" (do not forget to exchange "myapp" with your correct path name) I added to the "@Override" section the line:

    new RCTCameraPackage(),

in order to look like:

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new RCTCameraPackage(),
        new MainReactPackage());
    }
like image 97
olafguesswhapp Avatar answered Nov 15 '22 15:11

olafguesswhapp


This is related to a change that was made in React Native 0.18: https://github.com/facebook/react-native/commit/935cbb76c02cffd378a8f391c6e7443a3da13adc

In order to solve for it, I had to make sure to import the package at the correct location:

import com.lwansbrough.RCTCamera.RCTCameraPackage;

and reference it in the packages list:

new RCTCameraPackage(),

like so:

package com.myapp;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import com.lwansbrough.RCTCamera.RCTCameraPackage; // IMPORT REACT-NATIVE-CAMERA
import java.util.Arrays;
import java.util.List;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "myapp";
    }

    /**
     * Returns whether dev mode should be enabled.
     * This enables e.g. the dev menu.
     */
    @Override
    protected boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
    }

   /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
    @Override
    protected List<ReactPackage> getPackages() {

      return Arrays.<ReactPackage>asList(
        new RCTCameraPackage(), // ADD REACT-NATIVE_CAMERA
        new MainReactPackage()
      );
    }
}

Update: This fixed the error, but did not get the module working.

like image 36
Dan G Nelson Avatar answered Nov 15 '22 15:11

Dan G Nelson