You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo构建的React Native Android应用打开地图组件时崩溃

Expo构建APK后谷歌地图组件崩溃问题

我开发的Expo应用使用react-native-map-clustering(封装了react-native-maps)渲染MapView。通过Expo直接运行时完全正常,但构建APK并安装到Android模拟器后,每次打开地图组件,应用都会立刻崩溃退出。

组件代码

<MapView
  style={styles.map}
  provider={PROVIDER_GOOGLE}
  initialRegion={INITIAL_REGION}
  showsUserLocation
  showsMyLocationButton
  minZoom={2}
  maxZoom={20}
  clusterColor={COLORS.secondary}
  onRegionChangeComplete={async (region, markers) => {
    if(calculateRadius(region) > placesMapShow.raio){
      setPlacesMapShow({
        raio: Math.min(calculateRadius(region)/2, 10),
        latitude: region.latitude,
        longitude: region.longitude,
        latitudeDelta: region.latitudeDelta,
        longitudeDelta: region.longitudeDelta,
      });
      await refetch();
    }
  }}
>

app.json中Android配置部分

"android": {
  "adaptiveIcon": {
    "foregroundImage": "./assets/adaptive-icon.png",
    "backgroundColor": "#ccc"
  },
  "permissions": [
    "android.permission.ACCESS_COARSE_LOCATION",
    "android.permission.ACCESS_FINE_LOCATION",
    "android.permission.FOREGROUND_SERVICE"
  ],
  "package": "com.boucher.app",
  "versionCode": 1,
  "googleServicesFile": "./google-services.json",
  "config": {
    "googleMaps": {
      "apiKey": "******"
    }
  }
},

我知道需要在谷歌开发者平台和谷歌云之间配置SHA-1密钥才能让地图API密钥生效,但不清楚具体操作步骤。原本以为只要在app.json中配置API密钥,并给MapView设置PROVIDER_GOOGLE属性就能解决问题。

已尝试的方案

  • 在app.json的android.config.googleMaps.apiKey中配置地图API密钥,同时给MapView设置PROVIDER_GOOGLE属性;
  • 按照Expo MapView文档的建议,获取SHA-1并在谷歌云平台设置API密钥限制。

内容的提问来源于stack exchange,提问作者Joedson Santos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 07:16:03