react-native-camera无法在Android上读取未定义的属性'Constants'

时间:2019-05-25 06:38:25

标签: android reactjs react-native react-native-camera

我知道有this个问题。 我已经通过以下方式安装和配置了react-native-camera:

yarn add react-native-camera --save
react-native link react-native-camera 

将这些添加到 AndroidManifest.xml

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

我正在使用this基本代码:

 <RNCamera
          ref={ref => {
            this.camera = ref;
          }}
          style={styles.preview}
          type={RNCamera.Constants.Type.back}
          flashMode={RNCamera.Constants.FlashMode.on}
          androidCameraPermissionOptions={{
            title: 'Permission to use camera',
            message: 'We need your permission to use your camera',
            buttonPositive: 'Ok',
            buttonNegative: 'Cancel',
          }}
          androidRecordAudioPermissionOptions={{
            title: 'Permission to use audio recording',
            message: 'We need your permission to use your audio',
            buttonPositive: 'Ok',
            buttonNegative: 'Cancel',
          }}
          onGoogleVisionBarcodesDetected={({ barcodes }) => {
            console.log(barcodes);
          }}
        />

并得到此错误:

  

ExceptionsManager.js:74 TypeError:TypeError:无法读取未定义的属性“ Constants”

1 个答案:

答案 0 :(得分:0)

尝试这些:

  1. 通过打开MainApplication.java(app\src\main\java\com\YourAppName\MainApplication.java)文件来检查react-native链接是否起作用,如果发现与相机相关的内容,则搜索“ camera”,这意味着react-native链接起作用。如果找不到“相机”,则需要手动链接。

  2. 尝试卸载应用程序,关闭启动打包程序的所有终端,即react-native start。然后通过运行react-native run-android命令重新安装该应用程序。