如何手动生成google-services.json

时间:2017-07-14 17:08:39

标签: android google-cloud-messaging firebase-authentication firebase-cloud-messaging

我正在尝试将google-services.json添加到项目中。在Android工作室,我导航到' project'查看,我添加了' google-services.json'到应用程序'目录。 然后,我打开了google-services.json'文件和我唯一的改变是在' package_name'中添加项目的包名称。属于'客户'对象如google-services.json所示。

根据下面的链接-1,它说:

The main result of the JSON processing is to produce two XML files which you can reference as Android resources in your Java code... in

app/build/generated/res/google-services/{build_type}/values/values.xml

AND.

app/build/generated/res/google-services/{flavor}/{build_type}/xml/global_tracker.xml

但在我的情况下,我只有一个.xml文件,如下面的image-1所示。但是,如link-1中所述,可以通过创建.xml文件手动生成这些文件。

我提到link-1知道所需的值 - 请看image-2 - 我试图生成它但我找不到标有??????的值。请看下面的missing-values-file

1-请告诉我如何在???????中找到标有missing-values-file的缺失值?

2- server API key生成的Sender idGCM的目的是什么?为什么他们没有在missing-values-file

部分中发布的文件中使用

link-1:here

** link-2:配置文件是从here **

下载的

谷歌services.json : 包含' x'的值实际上是存在的,但为了安全起见,我删除了它们

{
"project_info": {
"project_number": "119xxx",
"project_id": "defxxx"
},
"client": [
{
  "client_info": {
    "mobilesdk_app_id": "1:1xxx",
    "android_client_info": {
      "package_name": "eu.xxx"
    }
  },
  "oauth_client": [
    {
      "client_id": "119xxx",
      "client_type": 3
    }
  ],
  "api_key": [
    {
      "current_key": "AIzxxx"
    }
  ],
  "services": {
    "analytics_service": {
      "status": 1
    },
    "appinvite_service": {
      "status": 1,
      "other_platform_oauth_client": []
    },
    "ads_service": {
      "status": 1
    }
  }
}
],
"configuration_version": "1"
}

图片-1

enter image description here

缺失值文件

<?xml version="1.0" encoding="utf-8"?>
<resources>

<! -- Present in all applications -->
<string name="google_app_id" translatable="false">1:1xxx</string>

<! -- Present in applications with the appropriate services configured -->
<string name="gcm_defaultSenderId" translatable="false">119xxx</string>
<string name="default_web_client_id" translatable="false">119xxxx</string>
<string name="ga_trackingId" translatable="false">??????</string>
<string name="firebase_database_url" translatable="false">???????</string>
<string name="google_api_key" translatable="false">???????</string>
<string name="google_crash_reporting_api_key" translatable="false">???????</string>

</resources>

图片-2

所需的值

enter image description here

1 个答案:

答案 0 :(得分:0)

要为项目生成配置文件和凭据,请按照creating an API project

中给出的步骤操作

然后,add the configuration file to your project

  

Gradle的Google服务插件解析google-services.json文件中的配置信息。通过更新顶级build.gradle和您的应用级build.gradle文件,将插件添加到您的项目中,如下所示:

     
      
  1. 将相关性添加到项目级build.gradle

         

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

  2.   
  3. 将插件添加到应用级build.gradle

         

    apply plugin: 'com.google.gms.google-services'

  4.   

有关其他见解,请参阅此相关SO post。这thread也可能会有所帮助。