我正在开发一个 React Native 应用程序,其中包含了一些 expo 库(裸露的工作流)。我已经成功使用了expo-location,但是现在我也安装了之后expo-camera,该应用程序将不再构建npm run android,尚未在 ios 上尝试。
它会在:expo-permissions:compileDebugKotlin步骤中崩溃。
我确实在另一个论坛上发现了这个问题,他们说要更新buildToolsVersionfrom build.gradleto29.0.2但它已经在29.0.2. 然后我更新react-native-unimodules了使用 expo 库所需的内容并包含 expo-permissions。它没有用。现在,我当前的库版本是:
"react-native-unimodules": "^0.12.0"
"expo-permissions": "~10.0.0"
"expo-camera": "^9.1.1"
Run Code Online (Sandbox Code Playgroud)
你有什么想法?有人也遇到过这个问题吗?
谢谢
更详细的堆栈跟踪是这样的:
Task :expo-permissions:compileDebugKotlin FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
153 actionable tasks: 4 executed, 149 up-to-date
e: app\node_modules\expo-permissions\android\src\main\java\expo\modules\permissions\PermissionsService.kt: …Run Code Online (Sandbox Code Playgroud) 我创建了一个项目,expo-camera点击按钮打开相机。但是,当我第一次单击该按钮时,仅呈现黑屏,重新打开屏幕并单击同一按钮后,相机 UI 会在屏幕上呈现。
我不知道为什么它首先显示黑屏。该问题仅存在于 android 设备中。
链接到 Expo Snack在 android 设备上试试这个例子。
import React, { useState, useEffect, useContext } from 'react';
import {
SafeAreaView,
View,
Text,
Dimensions,
ImageBackground,
Image,
Alert,
} from 'react-native';
import { Camera } from 'expo-camera';
import { Entypo, Ionicons, FontAwesome } from '@expo/vector-icons';
import { Surface, Button, TextInput } from 'react-native-paper';
const { width, height } = Dimensions.get('window');
let cameraRef;
const PickImage = ({ navigation }) => {
const [hasPermission, setHasPermission] = useState(null); …Run Code Online (Sandbox Code Playgroud) 我最近在一个托管博览会项目中更新了几行代码,与相机功能无关。iOS 上还是可以的,只是 Android 不行。我一个月前发布了一个运行良好的先前版本。但是,当我恢复到旧的提交时,它也无法在 Android 上运行(iOS 很好)。
启动相机等没有问题。相反,问题发生在 takePictureAsync 处,它挂起,然后不返回任何内容。
const snapPic = async () => {
const { status } = await Camera.getCameraPermissionsAsync();
if (status != 'granted') {
alert('Please grant access to camera and retry.');
await Camera.requestCameraPermissionsAsync();
return;
}
const options = { quality: 0.1 };
const photo = await this.camera.takePictureAsync(options);
this.camera.pausePreview();
this.setState({imageSource: photo.uri});
};
<Camera style={styles.cameraBox} ref={ref => {this.camera = ref}} />
Run Code Online (Sandbox Code Playgroud)
如有必要,请告诉我我可以提供哪些其他信息。提前致谢!
我正在以不同的方向(横向和纵向)录制一些视频,但我的应用程序被迫通过配置处于纵向模式。问题是每条记录的结果都是纵向保存的。
有没有办法在不改变配置的情况下决定结果方向?
这是我的相机组件:
import { Camera } from 'expo-camera'
...
private onStartRecording = () => {
if (this.ref.current && this.state.isCameraReady && this.isRightOrientation()) {
this.setState({ fileUrl: '', isRecording: true })
this.ref.current.recordAsync({ quality: '720p' })
.then((file) => {
if (this.props.format === 'horizontal' && !this.props.isVideo)
ImageManipulator.manipulateAsync(
file.uri,
[{ rotate: this.state.orientation }, { flip: ImageManipulator.FlipType.Horizontal }],
).then(file => {
this.setState({ fileUrl: file.uri })
}).then(error => console.log("Error", error))
else {
this.setState({ fileUrl: file.uri })
}
}).catch(error => console.log("Error", error));
}
}
...
return (
<Camera …Run Code Online (Sandbox Code Playgroud) 我是反应原生的新手。我创建了一个应用程序。但现在我想从这个应用程序捕获图像。我从世博会网站获得了代码,但问题是此代码只能打开相机。我想通过该相机捕捉图像。所以如果可能的话请帮助我..
这是我的代码
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import { Camera } from 'expo-camera';
import { Ionicons } from '@expo/vector-icons';
export default function App({navigation}) {
const [hasPermission, setHasPermission] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.back);
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
setHasPermission(status === 'granted');
})();
}, []);
if (hasPermission === null) {
return <View />;
}
if (hasPermission === false) { …Run Code Online (Sandbox Code Playgroud) 我正在使用 expo-camera 库来拍摄自拍图像。预览已镜像,但保存的图像将恢复为正常方向。如何防止这种效果发生(我希望图像保持镜像),或者如果不能,如何水平翻转图像?
到目前为止,我所拍摄的照片如下:
const takePic = async () => {
if (cameraRef) {
const photo = await cameraRef.current.takePictureAsync();
setFrontProfile(photo.uri);
}
};
Run Code Online (Sandbox Code Playgroud)