【发布时间】:2019-12-23 20:35:10
【问题描述】:
我对 expo 独立应用程序有疑问。问题在于位置的询问权限。在开发模式下,应用程序要求位置权限并且运行良好。没有错误。使用
构建应用程序后世博会构建:android
它创建了一个 android 独立应用程序。安装该 APK 并尝试访问请求位置权限的同一页面后,应用程序崩溃并重新启动。
我将权限添加到 app.json,但它不起作用。开发模式,一切正常。
app.json
"expo": {
"name": "AS APP",
"slug": "as_app",
"privacy": "public",
"sdkVersion": "32.0.0",
"android": {
"package": "com.xxx.asapp",
"icon": "./assets/icon.png",
"permissions": [
"ACCESS_COARSE_LOCATION",
"ACCESS_FINE_LOCATION",
"CAMERA",
"READ_EXTERNAL_STORAGE",
"WRITE_EXTERNAL_STORAGE"
]
},
"platforms": [
"ios",
"android"
],
"version": "1.10",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "cover",
"backgroundColor": "#781D7D"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.xxx.asapp"
},
"description": "",
}
请求位置权限
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if(this.state.isMounted){
if (status !== 'granted') {
Alert.alert(
'Permissions',
'please grant your permissions to access your location!',
[
{text: 'Ok', onPress: () => {
const popAction = StackActions.pop({n: 1});
this.props.navigation.dispatch(popAction);
}}
],
{cancelable: false},
);
}else{
let myLocation = await Location.getCurrentPositionAsync({
enableHighAccuracy: true,
});
let direction = await Location.geocodeAsync(this.props.navigation.getParam('address',null));
let myLocationAddress = await Location.reverseGeocodeAsync({
latitude: myLocation.coords.latitude,
longitude: myLocation.coords.longitude,
});
this.setState({
coordinates: [
{
latitude: myLocation.coords.latitude,
longitude: myLocation.coords.longitude
},
{
latitude: direction[0].latitude,
longitude: direction[0].longitude
},
],
myAddress: myLocationAddress
})
}
}
任何人都可以解决这个问题,请帮助我!
【问题讨论】:
-
你想通过 Android Studio 做一个应用吗?
-
我没有安装 android studio,我使用的是 vs code。
-
由于您将 Expo 做成一个独立的应用程序,您需要使用 Android Studio 构建它。
-
是的,没关系。但问题是这不是我第一次构建这个应用程序。每次我构建这个应用程序时它都可以工作。突然,我最后一次构建应用程序在询问权限时崩溃了。但在它工作之前..
-
如何使用android studio构建??我已经使用 expo build:android 构建了它。有错吗??
标签: javascript react-native expo android-permissions