不同 productFlavors 的 google-services.json [英] google-services.json for different productFlavors

查看:34
本文介绍了不同 productFlavors 的 google-services.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

更新:

有多少 google-services.json 文件取决于您的项目特征,但您至少需要为每个 Google 项目提供一个 JSON 文件.

如果您想了解有关此插件如何处理这些 JSON 文件的更多详细信息,请访问:https://github.com/googlesamples/google-services/issues/54#issuecomment-165824720

官方文档链接:https://developers.google.com/android/guides/google-services-插件

包含更新信息的博文:https://firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html

去这里查看这个插件的最新版本:https://mvnrepository.com/artifact/com.google.gms/google-services?repo=google

Update: GCM is deprecated, use FCM

I'm implementing the new Google Cloud Messaging following the guides from the Google Developers page here

I've successfully run and test it. But my problem now is I have different product flavors with different applicationId/packageName and different Google Cloud Messaging Project Id. The google-services.json have to be put at the /app/google-services.json not the flavors folder.

Is there any way to make the google-services.json config different for many flavors?

解决方案

Google included support for flavors in version 2.0 of the play services plugin. Since this version of the gradle plugin com.google.gms:google-services:2.0.0-alpha3

you can do this

Step 1: add to gradle

// To auto-generate google map api key of google-services.json
implementation 'com.google.android.gms:play-services-maps:17.0.0'

Step 2: add to AndroidManifest.xml in the application tag

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_api_key" />

Step 3: download each flavor JSON file from firebase and add it

app/src/
    flavor1/google-services.json
    flavor2/google-services.json

Version 3.0.0 of the plugin searches for the JSON file in these locations (considering you have a flavor flavor1 and a build type debug):

/app/src/debug/google-services.json
/app/src/debug/flavor1/google-services.json
/app/google-services.json

This worked for me even using flavorDimensions. I have free & paid in one dimension and Mock & Prod in the other dimension. I also have 3 buildTypes: debug, release, and staging. This is how it looks in my project for the FreeProd flavor:

How many google-services.json files will depend on your project's characteristics, but you will need at least one JSON file for every Google project.

If you want more details about what this plugin does with these JSON files, here it is: https://github.com/googlesamples/google-services/issues/54#issuecomment-165824720

Link to the official docs: https://developers.google.com/android/guides/google-services-plugin

Blog post with updated info: https://firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html

And go here to check the latest version of this plugin: https://mvnrepository.com/artifact/com.google.gms/google-services?repo=google

这篇关于不同 productFlavors 的 google-services.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆