繁体   English   中英

Flutter 谷歌地图 - API 密钥未找到

[英]Flutter google maps - API key not found

我正在尝试按照教程在 flutter 中设置谷歌地图,但我遇到了一些问题。 我的应用程序运行,但我看到一个白屏,没有任何事情发生,并且以下错误被打印到终端:

E/MethodChannel#flutter/platform_views(13225): Failed to handle method call
E/MethodChannel#flutter/platform_views(13225): 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

这很奇怪,因为我的AndroidManifest.xml看起来像这样:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.studievriend">
    <!-- 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"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application>
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIxxxxxxxxxxx-xxxxxxxxxxxxxxx_xxxxxx"/>
    </application>
</manifest>

这正是错误所要求的,所以我不知道出了什么问题。 我查看了其他线程并做了一些建议的事情,比如运行删除应用程序、 flutter cleanflutter run ,这也不起作用。

这些是我在pubspec.yaml中的依赖项

dependencies:
  flutter:
    sdk: flutter
  location: ^4.1.1
  cloud_firestore: ^1.0.5
  firebase_core: ^1.0.3
  google_maps_flutter: ^2.0.3

我也想添加geoflutterfire: ^2.0.2 ,但随后出现以下错误

Because geoflutterfire >=2.2.2 <3.0.0-nullsafety.1 depends on cloud_firestore ^0.16.0 and studievriend depends on cloud_firestore ^1.0.5, geoflutterfire >=2.2.2 <3.0.0-nullsafety.1 is forbidden.

So, because studievriend depends on geoflutterfire ^2.2.2, version solving failed.

我也尝试了一些其他版本,但我不断收到错误。

如果有人可以帮助我,我将不胜感激!

您使用了错误的 AndroidManifest.xml。 请使用app目录下的AndroidManifest.xml,而不是debug目录下。 调试清单仅用于 flutter 本身。 正确的应该在这个位置:

android\app\src\main\AndroidManifest.xml

对于您的其他错误,您可能需要导入较低版本的 geoflutterfire,因为存在版本冲突。 您导入了 cloud_firestore: ^1.0.5 但 geofluttefire 依赖于较新的版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM