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

Flutter集成Google Maps时提示API Key未找到的问题求助

解决Flutter集成Google Maps时的API Key未找到问题

我一眼就发现问题所在了!你把Google Maps API Key对应的<meta-data>标签放错位置啦😉

问题根源

你的AndroidManifest.xml里,API Key的配置被嵌套在了<activity>标签内:

<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyBM8ywYw1UDb3aXaTF3w21EJ86ePWmAkPE"/>

但错误日志明确要求,这个<meta-data>必须直接放在<application>元素下,不能被<activity>包裹。

修正步骤

把这段API Key的配置移到<application>标签下,和<activity>同级即可。修改后的完整AndroidManifest.xml如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.foody.foody">
    <!-- The INTERNET permission is required for development. Specifically, flutter needs it to communicate with the running application to allow setting breakpoints, to provide hot reload, etc. -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that calls FlutterMain.startInitialization(this); in its onCreate method. In most cases you can leave this as-is, but you if you want to provide additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. -->
    <application android:name="io.flutter.app.FlutterApplication" android:label="foody" android:icon="@mipmap/ic_launcher">
        <!-- 把API Key的meta-data移到这里,和activity同级 -->
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyBM8ywYw1UDb3aXaTF3w21EJ86ePWmAkPE"/>
        <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing until Flutter renders its first frame. It can be removed if there is no splash screen (such as the default splash screen defined in @style/LaunchTheme). -->
            <meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

额外检查(以防还有问题)

  • 确认你的API Key已经在Google Cloud Console中启用了Maps SDK for Android服务
  • 检查API Key的限制设置:如果做了应用限制,要确保包名com.foody.foody和SHA-1指纹配置完全正确
  • 清理项目缓存:执行flutter clean命令后,再重新运行应用

调整完位置后,应该就能顺利加载地图啦!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:04:25