Search code examples
react-nativeexpoexpo-camera

expo-camera: Error: Permissions module is null


I have an error in console after to install expo-camera.

  1. expo install expo-camera
  2. add permission in android manifest
  3. add module expo camera in maven

allprojects { repositories {

    // * Your other repositories here *

    // * Add a new maven block after other repositories / blocks *
    maven {
        // expo-camera bundles a custom com.google.android:cameraview
        url "$rootDir/../node_modules/expo-camera/android/maven"
    }
}

}

  1. start the protect

  2. click on the button to show camera ... error in log

    Error: Permissions module is null.

Permission:

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

update 1 : I test with this code example to check my permission https://reactnative.dev/docs/permissionsandroid my example function

 // state local
 const [hasPermission, setHasPermission] = useState(null);
 // function
 const requestCameraPermission = async () => {
        console.log('requestCameraPermission')
        try {
            const granted = await PermissionsAndroid.request(
                PermissionsAndroid.PERMISSIONS.CAMERA,
                {
                    title: "Cool Photo App Camera Permission",
                    message:
                        "Cool Photo App needs access to your camera " +
                        "so you can take awesome pictures.",
                    buttonNeutral: "Ask Me Later",
                    buttonNegative: "Cancel",
                    buttonPositive: "OK"
                }
            );
            if (granted === PermissionsAndroid.RESULTS.GRANTED) {
                setHasPermission(true)
                console.log("You can use the camera");
            } else {
                console.log("Camera permission denied");
                setHasPermission(false)
            }
        } catch (err) {
            console.warn(err);
        }
    };

   // result of requestCameraPermission : You can use the camera
  //  Error  : Attempt to invoke interface method 'boolan expo.modules.interfaces.permission.Permission.hasGrantedPermissions(java.lang.string[]) on a null object reference

I make something wrong ? thanks for help


Solution

  • If you did just these steps, you have to do more things to make it works on Android device.

    Github page says:

    Adjust the android/build.gradle to add a new maven block after all other repositories as described below:

    allprojects {
        repositories {
    
            // * Your other repositories here *
    
            // * Add a new maven block after other repositories / blocks *
            maven {
                // expo-camera bundles a custom com.google.android:cameraview
                url "$rootDir/../node_modules/expo-camera/android/maven"
            }
        }
    }
    

    But before do that, you should:

    For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules package before continuing.