【问题标题】:java.lang.RuntimeException: API key not foundjava.lang.RuntimeException:未找到 API 密钥
【发布时间】:2019-11-03 09:52:05
【问题描述】:

我是 Flutter 新手,正在使用谷歌地图服务尝试 Flutter,我的 Android Manifest 如下所示,我的 api 密钥也受到限制:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.succo.succo">
    <!-- 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="my real key."/>
    </application>
</manifest>

当我尝试运行 Flutter 应用程序时,我不断收到错误提示 java.lang.RuntimeException: API key not found,然后整个错误日志如下所示:

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
I/flutter ( 5552): Overflow on channel: flutter/lifecycle.  Messages on this channel are being discarded in FIFO fashion.  The engine may not be running or you need to adjust the buffer size if of the channel.
I/zzbz    ( 5552): Making Creator dynamically
D/        ( 5552): HostConnection::get() New Host Connection established 0xceaeab80, tid 5566
D/EGL_emulation( 5552): eglMakeCurrent: 0xe2e0f5e0: ver 2 0 (tinfo 0xe2e10610)
I/flutter ( 5552): current location is:
I/flutter ( 5552): 37.4219983
I/flutter ( 5552): -122.084
W/com.succo.succ( 5552): Unsupported class loader
W/com.succo.succ( 5552): Skipping duplicate class check due to unsupported classloader
I/DynamiteModule( 5552): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221
I/DynamiteModule( 5552): Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
V/DynamiteModule( 5552): Dynamite loader version >= 2, using loadModule2NoCrashUtils
W/com.succo.succ( 5552): Unsupported class loader
W/com.succo.succ( 5552): Skipping duplicate class check due to unsupported classloader
I/Google Maps Android API( 5552): Google Play services client version: 12451000
I/Google Maps Android API( 5552): Google Play services package version: 19420040
E/MethodChannel#flutter/platform_views( 5552): Failed to handle method call
E/MethodChannel#flutter/platform_views( 5552): 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
E/MethodChannel#flutter/platform_views( 5552):  at com.google.maps.api.android.lib6.drd.p.b(:com.google.android.gms.dynamite_mapsdynamite@19420084@19.4.20 (100700-271418971):22)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.maps.api.android.lib6.auth.d.a(:com.google.android.gms.dynamite_mapsdynamite@19420084@19.4.20 (100700-271418971):80)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.maps.api.android.lib6.impl.d.a(:com.google.android.gms.dynamite_mapsdynamite@19420084@19.4.20 (100700-271418971):41)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms.dynamite_mapsdynamite@19420084@19.4.20 (100700-271418971):54)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.maps.internal.CreatorImpl.newMapViewDelegate(:com.google.android.gms.dynamite_mapsdynamite@19420084@19.4.20 (100700-271418971):32)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.maps.internal.h.a(:com.google.android.gms.dynamite_mapsdynamite@19420084@19.4.20 (100700-271418971):62)
E/MethodChannel#flutter/platform_views( 5552):  at cv.onTransact(:com.google.android.gms.dynamite_mapsdynamite@19420084@19.4.20 (100700-271418971):4)
E/MethodChannel#flutter/platform_views( 5552):  at android.os.Binder.transact(Binder.java:667)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.internal.maps.zza.zza(Unknown Source:10)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.maps.internal.zzf.zza(Unknown Source:19)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.maps.MapView$zzb.createDelegate(Unknown Source:13)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaa(Unknown Source:18)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreate(Unknown Source:22)
E/MethodChannel#flutter/platform_views( 5552):  at com.google.android.gms.maps.MapView.onCreate(Unknown Source:26)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugins.googlemaps.GoogleMapController.init(GoogleMapController.java:136)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugins.googlemaps.GoogleMapBuilder.build(GoogleMapBuilder.java:32)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugins.googlemaps.GoogleMapFactory.create(GoogleMapFactory.java:51)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:174)
E/MethodChannel#flutter/platform_views( 5552):  at android.app.Dialog.dispatchOnCreate(Dialog.java:407)
E/MethodChannel#flutter/platform_views( 5552):  at android.app.Dialog.show(Dialog.java:302)
E/MethodChannel#flutter/platform_views( 5552):  at android.app.Presentation.show(Presentation.java:249)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugin.platform.VirtualDisplayController.<init>(VirtualDisplayController.java:93)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:53)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:105)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:96)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#flutter/platform_views( 5552):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:645)
E/MethodChannel#flutter/platform_views( 5552):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter/platform_views( 5552):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#flutter/platform_views( 5552):  at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#flutter/platform_views( 5552):  at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#flutter/platform_views( 5552):  at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter/platform_views( 5552):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#flutter/platform_views( 5552):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

【问题讨论】:

    标签: google-maps flutter


    【解决方案1】:

    这有点棘手,AndroidManifest.xml 文件有两个,profile/ 下一个,main/ 下一个,你需要将 API 密钥添加到 main/ 下的清单文件中。

    【讨论】:

      【解决方案2】:

      我在manifest 中都添加了密钥:

      • main/ 下的一个
      • profile/中的另一个

      现在它开始工作了。

      【讨论】: