簡體   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