【问题标题】:Expo android standalone app crashes when ask location permissions询问位置权限时,Expo android 独立应用程序崩溃
【发布时间】: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


【解决方案1】:

升级您的 expo cli 和 expo sdk,如果太新则降级

【讨论】:

  • 这不是与博览会相关的错误!
猜你喜欢
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-15
  • 2021-09-21
  • 2019-06-25
  • 2022-11-28
相关资源
最近更新 更多