开关GCM客户端的开发与生产客户端、GCM

2023-09-07 12:05:22 作者:十友九狗

刚刚实施新的GCM。对于正式文件,

Just implement the new GCM. For official document,

复制您刚刚下载到你的Andr​​oid Studio项目的应用程序/或移动/目录下的谷歌,services.json文件。

Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.

任何人都知道的设置如何摇篮切换开发和生产使用不同的谷歌,services.json?

Anyone know how to setup gradle to switch development and production to use different google-services.json?

推荐答案

我刚才此处回答过类似的问题不同的 productFlavors

在你的情况下,它的调试/生产。我不知道为什么你需要制作和调试之间切换,但我认为你可以做一样的东西,我提议为风味。

In your case it's debug/production. I don't know why you need to switch between production and debug but i think you can do the same as what I proposed for flavors.

创建两个额外的文件夹的src /发布的src /调试,在每一个你把相应的文件夹谷歌services.json ,所以你将有:的src /发行/谷歌services.json 的src /调试/谷歌services.json

Create two extra folders src/release and src/debug , in each of the folders you put the corresponding google-services.json , so you will have: src/release/google-services.json and src/debug/google-services.json

现在在摇篮补充一点:

android {

// set build config here to get the right gcm configuration.
//def myBuildConfig = "release"
def myBuildConfig = "debug"

// this will copy the right google-services.json file to app/ directory.
if (myBuildConfig.equals("release")) {
    println "--> release copy!"
    copy {
        from 'src/release/'
        include '*.json'
        into '.'
    }
} else {
    println "--> debug copy!"
    copy {
        from 'src/debug/'
        include '*.json'
        into '.'
    }
}

// other stuff
}