android - 如何使用 Android Studio 为同一项目中的不同谷歌服务集成两个或多个 google-services.json 文件

标签 android android-studio google-play-services

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

So, how can I integrate both google-services.json configuration file in my project.

这是我的配置文件之一

{
  "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"
}

最佳答案

最后我做了如下:

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

第 2 步: 检查两个配置文件,它在 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

关于android - 如何使用 Android Studio 为同一项目中的不同谷歌服务集成两个或多个 google-services.json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35012700/

相关文章:

android - 使用 JSoup 从 WebView 中删除 Div

外部 SD 卡上的 Android 应用程序文件夹

android - 垃圾回收导致 : MediaPlayer finalized without being released

java - 将java文件夹添加到android studio项目

android - 呈现问题 : Android Studio 2. 2 - 约束布局

android - 查找尝试连接到 Android 设备的进程

android - 适用于 Android 的 Google 应用邀请 : Reward sender

android - GCM 示例项目错​​误消息 "Could not find google-play-services_lib.apk"

android - 如何执行 "RXJava 2 queue jobs"直到值改变?

android - 我如何使用旧版本的谷歌播放服务?