google-services.json api_key在firebase中是空的

时间:2018-05-16 22:48:07

标签: firebase flutter google-play-services

当我关注https://codelabs.developers.google.com/codelabs/flutter-firebase/并且我下载了google-services.json时,我尝试在Android上运行flutter应用时遇到此错误。

checkIfNonZero():boolean{
  const a=0;
  const b=1;
  const c=0;
  const d=0;
  //Regular way would be as below. 
  //How can this use some library instead of doing comparison for each variable
  if(a>0 || b>0 || c>0 || d>0){
   return true;
  }
  return false;
}

现在在我的google-services.json中我可以看到api_key数组是emtpy:

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:processDebugGoogleServices'. > Missing api_key/current_key object * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. * Get more help at https://help.gradle.org BUILD FAILED in 21s Finished with error: Gradle build failed: 1

我尝试下载新的google-services.json但结果相同。

任何人都知道如何生成api_key?

1 个答案:

答案 0 :(得分:1)

首先,访问Firebase控制台。

选择您的项目,访问“项目设置”(可通过​​单击“项目概述”访问)。

现在,点击“3点”,然后点击“设置”。

在“项目设置”屏幕上,复制“Web API密钥”(例如:AIzaSyAjo3TYy8p_mjj3jMDcxTPrkwDF2dL8lwl)。

现在转到您的项目并转到“google-services.json”文件(位于“\ android \ app \ google-services.json”下)

在文件代码“google-services.json”中找到包含以下代码的行:

"api_key": [],

括号内“[]”输入以下代码:

{
  "current_key": "<paste here your Web API Key>"
}

将Web API密钥粘贴在双引号之间(请参阅下面的示例):

"api_key": [
    {
      "current_key": "AIzaSyAjo3TYy8p_mjj3jMDcxTsdFkwDF2dL8NWs"
    }
],