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

React Native Map集成定位后打包APK崩溃问题求助

解决React Native Expo打包APK后地图组件崩溃问题

问题背景

基于React Native集成地图组件并获取用户定位,开发环境通过npx expo start运行无报错、卡顿问题,但打包为APK安装后应用直接崩溃。

使用的依赖版本:

  • "react-native": "0.70.5"
  • "expo": "~47.0.12"
  • "expo-location": "~15.0.1"
  • "@react-native-community/geolocation": "^3.0.4"
  • "react-native-maps": "^1.3.2"

崩溃日志

FATAL EXCEPTION: expo-updates-error-recovery

java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml

FATAL EXCEPTION: expo-updates-error-recovery
Process: com.flokitoto.mapauthentificate, PID: 14044
java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml

解决方案

1. 获取Google Maps API密钥

  • 登录Google Cloud控制台,创建或选择当前项目
  • 搜索并启用Maps SDK for Android服务
  • 创建API密钥,建议限制密钥仅用于你的应用包名(com.flokitoto.mapauthentificate)和SHA-1指纹,避免密钥滥用

2. 配置AndroidManifest.xml

打开项目的AndroidManifest.xml文件,在<application>标签内部添加API密钥的meta-data配置:

<application 
  android:name=".MainApplication" 
  android:label="@string/app_name" 
  android:icon="@mipmap/ic_launcher" 
  android:roundIcon="@mipmap/ic_launcher_round" 
  android:allowBackup="true" 
  android:theme="@style/AppTheme" 
  android:usesCleartextTraffic="true">
  
  <!-- 已有的其他meta-data -->
  <meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
  <!-- 添加以下Google Maps API密钥配置 -->
  <meta-data android:name="com.google.android.geo.API_KEY" android:value="你的Google Maps API密钥"/>
  
  <!-- 已有的activity配置 -->
  <activity android:name=".MainActivity" ...>
    <!-- ... -->
  </activity>
</application>

3. Expo Managed Workflow 额外配置

如果你使用的是Expo managed workflow,也可以直接在app.json中配置API密钥,Expo会自动同步到AndroidManifest:

{
  "expo": {
    "android": {
      "config": {
        "googleMaps": {
          "apiKey": "你的Google Maps API密钥"
        }
      }
    }
  }
}

4. 验证配置

重新打包APK并安装测试,确认应用不再崩溃,地图组件能正常加载。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 22:15:26