expo-camera: Error: Permissions module is null
expo-camera: Error: Permissions module is null
我在安装 expo-camera 后控制台出现错误。
- expo 安装 expo-camera
- 在 android 清单中添加权限
- 在 maven 中添加模块 expo camera
所有项目{
存储库 {
// * 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"
}
}
}
启动保护
点击按钮显示相机...日志中出现错误
错误:权限模块为空。
权限:
<uses-permission android:name="android.permission.CAMERA" />
更新 1:
我使用此代码示例进行测试以检查我的权限
https://reactnative.dev/docs/permissionsandroid
我的示例函数
// 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
我做错了什么?
感谢帮助
如果您只执行了这些步骤,则必须执行更多操作才能使其在 Android 设备上运行。
Github page 说:
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"
}
}
}
但在此之前,您应该:
For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules package before continuing.
我在安装 expo-camera 后控制台出现错误。
- expo 安装 expo-camera
- 在 android 清单中添加权限
- 在 maven 中添加模块 expo camera
所有项目{ 存储库 {
// * 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"
}
}
}
启动保护
点击按钮显示相机...日志中出现错误
错误:权限模块为空。
权限:
<uses-permission android:name="android.permission.CAMERA" />
更新 1: 我使用此代码示例进行测试以检查我的权限 https://reactnative.dev/docs/permissionsandroid 我的示例函数
// 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
我做错了什么? 感谢帮助
如果您只执行了这些步骤,则必须执行更多操作才能使其在 Android 设备上运行。
Github page 说:
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"
}
}
}
但在此之前,您应该:
For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules package before continuing.