致命异常:java.lang.SecurityException:无效的 API 密钥

Fatal Exception: java.lang.SecurityException: Invalid API Key

我崩溃了

Crashed: main
       at android.os.Parcel.createException + 1969(Parcel.java:1969)
       at android.os.Parcel.readException + 1935(Parcel.java:1935)
       at android.os.Parcel.readException + 1885(Parcel.java:1885)
       at com.google.android.gms.common.internal.IGmsServiceBroker$Stub$zza.getService + 14(:14)
       at com.google.android.gms.common.internal.BaseGmsClient.getRemoteService + 244(:244)
       at com.google.android.gms.common.api.internal.zaaq.zaan + 6(:6)
       at com.google.android.gms.common.api.internal.zaau.run + 6(:6)
       at java.util.concurrent.Executors$RunnableAdapter.call + 458(Executors.java:458)
       at java.util.concurrent.FutureTask.run + 266(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
       at com.google.android.gms.common.util.concurrent.zza.run + 6(:6)
       at java.lang.Thread.run + 764(Thread.java:764)

Fatal Exception: java.lang.SecurityException: Invalid API Key for package = com.Filmgrail.android.bergen_dev. Status code received = 12
       at android.os.Parcel.createException + 1969(Parcel.java:1969)
       at android.os.Parcel.readException + 1935(Parcel.java:1935)
       at android.os.Parcel.readException + 1885(Parcel.java:1885)
       at com.google.android.gms.common.internal.IGmsServiceBroker$Stub$zza.getService + 14(:14)
       at com.google.android.gms.common.internal.BaseGmsClient.getRemoteService + 244(:244)
       at com.google.android.gms.common.api.internal.zaaq.zaan + 6(:6)
       at com.google.android.gms.common.api.internal.zaau.run + 6(:6)
       at java.util.concurrent.Executors$RunnableAdapter.call + 458(Executors.java:458)
       at java.util.concurrent.FutureTask.run + 266(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
       at com.google.android.gms.common.util.concurrent.zza.run + 6(:6)
       at java.lang.Thread.run + 764(Thread.java:764)

我检查了包名,API_KEY没问题。 我尝试生成新的 API_KEY,下载新的 google-services.json 并且应用程序在我的设备上运行良好,但其他一些用户遇到此崩溃。

我使用:

    implementation 'com.google.firebase:firebase-config:19.0.0'
    implementation 'com.google.firebase:firebase-core:17.1.0'
    implementation 'com.google.firebase:firebase-analytics:17.1.0'
    implementation "com.google.android.gms:play-services-ads:18.1.1"
    implementation "com.google.android.gms:play-services-auth:17.0.0"
    implementation "com.google.android.gms:play-services-gcm:17.0.0"
    implementation 'com.google.android.gms:play-services-analytics:17.0.0'
    implementation "com.google.android.gms:play-services-location:17.0.0"
    implementation "com.google.android.gms:play-services-identity:17.0.0"

    classpath 'com.google.gms:google-services:4.2.0'

    classpath 'com.android.tools.build:gradle:3.5.0'

我不知道如何解决这个问题。 请帮助我

您需要将 App id 添加到清单文件中。下面的代码可以帮到你。

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