【问题标题】:How to integrate two or more google-services.json file together for different google service in same project using Android Studio如何使用 Android Studio 将两个或多个 google-services.json 文件集成在一起以用于同一项目中的不同 google 服务
【发布时间】:2016-05-02 22:46:18
【问题描述】:

我正在制作一个项目,我想在其中集成 GCMGoogle sign in,但问题是两者都有 google-services.json 配置文件,我们需要将其添加到我们的项目中。

那么,我怎样才能同时集成google-services.json 配置 我的项目中的文件。

这是我的一个配置文件

{
  "project_info": {
    "project_id": "default-xxx",
    "project_number": "xxx",
    "name": "xxx"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:xxx",
        "client_id": "x.package",
        "client_type": 1,
        "android_client_info": {
          "package_name": "x.package_name"
        }
      },
      "oauth_client": [],
      "api_key": [],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "cloud_messaging_service": {
          "status": 1,
          "apns_config": []
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "google_signin_service": {
          "status": 1
        },
        "ads_service": {
          "status": 1
        }
      }
    }
  ],
  "client_info": [],
  "ARTIFACT_VERSION": "1"
}

【问题讨论】:

标签: android android-studio google-play-services


【解决方案1】:

最后我做了如下:

第 1 步: 打开您想要的 google 服务页面,在我的例子中是 google sign inGCM。会有一个按钮说获取配置文件,点击它并输入您的详细信息并获取配置文件。

第二步:检查两个配置文件,它在 project_info 对象和 client_info 对象中具有相同的配置。区别在于 services 对象,如果您添加了两个或更多服务,则必须检查状态,status 值将是 2 这意味着它们是启用的服务。您可以在下面的配置文件中看到我为 Google 登录GCM 这两个服务生成的配置文件。

您只需要检查您在 services 对象中的 status 值,其中表示您已集成到项目中的所有服务的 2是你必须添加的配置文件。

{
  "project_info": {
    "project_id": "xxxxxxxxxx",
    "project_number": "xxxxxxxx",
    "name": "xxxxxxxxxxx"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "xxxxxxxxxxx",
        "client_id": "xxxxxxxxxxx",
        "client_type": 1,
        "android_client_info": {
          "package_name": "xxxxxxxxxx"
        }
      },
      "oauth_client": [
        {
          "client_id": "xxxxxxxxxx",
          "client_type": 1,
          "android_info": {
            "package_name": "xxxxxxxx",
            "certificate_hash": "xxxxxxxxxxx"
          }
        }
      ],
      "api_key": [],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "cloud_messaging_service": {
          "status": 2, <======= this is my gcm service status
          "apns_config": []
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "google_signin_service": {
          "status": 2   <===== this my google sign in service status
        },
        "ads_service": {
          "status": 1
        }
      }
    }
  ],
  "client_info": [],
  "ARTIFACT_VERSION": "1"
}

注意:我正在使用 Google 登录 服务,因此它会生成 oauth_client 字段值,如果您只生成该字段值,您也不会得到GCM

【讨论】:

    【解决方案2】:

    您不需要两个不同的 google-services.json 文件。两者将具有相同的配置。无论您激活了多少服务,这些配置文件对于每个项目都是唯一的。

    在生成配置文件之前,请确保您已激活这两个服务。生成的配置文件对两者都有效。

    点击“下载并安装配置”链接下方的“继续登录”链接,获取有关下一步操作的文档。

    【讨论】:

    • 感谢您的解决方案,在为两个或多个谷歌服务创建时,您必须查看的服务状态配置文件有一些变化
    • 随着您不断添加服务,google-services.json 会更新。因此,您下载的最后一个文件已激活所有服务。
    • 是的,我明白了,我已经发布了我的解决方案以及我所做的一些更改。
    • 对于任何未来的读者,在某些情况下您需要 2 个不同的版本,例如 google-services.json 的修改版本,即。对于具有不同 package_name 属性的风味。
    猜你喜欢
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 2019-01-07
    • 2017-10-19
    • 1970-01-01
    相关资源
    最近更新 更多